C++ – how to convert string into an integer in a batch file

batch-filecpre-build-eventstringvisual studio 2010

I have this piece of batch file :

@echo off
set  xx=7
echo the version is %xx%

I wand to use it in a pre-build event in VS2010 – as an integer :

MY_INT = $(xx)

but it's value is a string , how can I convert the string value into an integer value in the batch file?

thanks!

Best Answer

Environment variables (batch variables) are always strings; they cannot be stored as integers.

The SET command with the /A option can parse integral numbers from strings, perform arithmetic operations, and store the integral result in an environment variable. But the final result is still a string representation of the final number.

Type help set or set /? from a command prompt for more info about the SET /A option.