1

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!

user1386966
  • 3,302
  • 13
  • 43
  • 72

1 Answers1

2

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.

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • thanks! it there a way to define environment varaibles using .bat file? how can I do it? – user1386966 Dec 09 '12 at 18:24
  • @user1386966 - Umm... That is what the SET command is for. I said as much already in the answer. – dbenham Dec 09 '12 at 19:37
  • 1
    Watch out for **set /A SomeVariable = 08** or **set /A SomeVariable = 09** Batch treats 0 prefixed numbers as Octal instead of decimal. check [this link](http://www.robvanderwoude.com/ntset.php) – WeSam Abdallah Jul 09 '13 at 15:28