What does the batch variable mean set =% variable: ~ 1%

Can someone explain what is :~1% in the following expression in a batch file? I assigned the value %variable the server name and tried echo %variable . I get the same server name as the output. Can someone explain how the description below works?

 set variable=%variable:~1% 
+6
source share
2 answers

This is the substring syntax from the contents of the variable, in which case it removes the first character.

See set /? for reference

+4
source

This is a notation for expanding a substring of a string; look at this command line with a ready-made form that you will understand.

 C:\>set temp=stackoverflow.com C:\>echo %temp% stackoverflow.com C:\>echo %temp:~5% overflow.com C:\>echo %temp:~5,8% overflow C:\> 

if you do not understand, here is the syntax (in my opinion)

 set variable=%variable:~startingCharector [,OptionalLenghtOfCharctors]% 

Where

OptionalLenghtOfCharctors by default, it accepts the remaining characters of the string.

+3
source

All Articles