Left String

Extract characters from the beginning of a string.

Description: Similar to the Left function in VB a batch script can return a specified number of characters from the left side of a string by specifying a substring for an expansion given a position of 0 and a length using :~ while expanding a variable content. The example shows how to return the first 4 characters of a string.
Script:
1.
2.
3.
4.
set str=politic
echo.%str%
set str=%str:~0,4%
echo.%str%
Script Output:
 DOS Script Output
politic
poli