To substring a string variable in Dos use following syntax.
%variable name:~N,L%
where
variable name = any variable with a string value
N = Zero based index from which the substring should be started.
L = Length of substring. If ommited full string from starting index is returned.
The substring can be very usefull in dos specially when we want to format Date. e.g. if we want to take the first two character of string
set alpha = abcdefghi
echo value of variable is = %alpha%
echo substring value is = %alpha:~0,6%
Output:
value of variable is = abcdefghi
substring value is = abcdef
%variable name:~N,L%
where
variable name = any variable with a string value
N = Zero based index from which the substring should be started.
L = Length of substring. If ommited full string from starting index is returned.
The substring can be very usefull in dos specially when we want to format Date. e.g. if we want to take the first two character of string
set alpha = abcdefghi
echo value of variable is = %alpha%
echo substring value is = %alpha:~0,6%
Output:
value of variable is = abcdefghi
substring value is = abcdef
No comments:
Post a Comment