Batch Script - toInt


Advertisements

A variable which has been set as string using the set variable can be converted to an integer using the /A switch which is using the set variable. The following example shows how this can be accomplished.

Example

@echo off
set var = 13145
set /A var=%var% + 5
echo %var%

Output

The above command produces the following output.

13150

Apart from this, strings have the following implementations which are available. Batch scripts have the following commands which are used to carry out string manipulation in strings.

%variable:~num_chars_to_skip% 
%variable:~num_chars_to_skip,num_chars_to_keep%

This can include negative numbers −

%variable:~num_chars_to_skip, -num_chars_to_keep%
%variable:~-num_chars_to_skip,num_chars_to_keep%
%variable:~-num_chars_to_skip,-num_chars_to_keep%

Let us discuss the possible string operations that can be performed by using the above commands.

batch_script_strings.htm
Advertisements