I have a variable defined in a batch file as follows
set "SERVERNAME=VKR\SQL2012"
I need to extract VKR from this. Is there a way I could do this?
I tried this
set "value=%SERVERNAME:*\=%"
echo %value%
which returned SQL2012 but not VKR
I have a variable defined in a batch file as follows
set "SERVERNAME=VKR\SQL2012"
I need to extract VKR from this. Is there a way I could do this?
I tried this
set "value=%SERVERNAME:*\=%"
echo %value%
which returned SQL2012 but not VKR
You can do this to take the first three characters (assuming it's a fixed length):
set "SERVERNAME=VKR\SQL2012"
set "value=%SERVERNAME:~0,3%"
echo %value%
Another way:
set "SERVERNAME=VKR\SQL2012"
set "value=%SERVERNAME:\=" & rem "%"
echo %value%
echo on to see exactly what is executed. You may see another example of this technique at this answer.%variable% expansion is done before the resulting line is parsed for special characters, like &<|>. Try: set "test=echo one & echo two" followed by %test%