colon tilde in windows batch scripting

Tilde is an interesting symbol in windows batch script. You may have seen %~0. The tilde before the digit (which means the command name) does something  special to the parameter. Colon is also a useful symbol in windows bat file. Colon is used to replace a substring of a variable with another. So %var:substring1=substring2% will replace all occurrences of substring1 of %var% with  substring2. What about the colon-tilde combination?  :~ is used to get a substring of a variable. So %var:~0,1% will get the first character of %var%. %var:~0,2% will get the first two characters of %var%. %var:~1,2% will get the substring starting from index 1 and of the length 2. %var:~0,-1% get the sub-string starting from index 0 to(excluding) the last character so %var:~0,-1% actually remove the last character of %var%. %var:~10% get the sub-string from index 10 to the end of %var%. For more details, please refer to this post.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply