4

I have a variable read from a file:

%var%=13,145

I want to add this value to another value:

set /a %var%=%var%+5

but the result is 13+5, not 13145+5.

How can I delete this "," from my string?

1 Answer 1

13

Do not add commas.

set var=13145

And also, when assigning a variable, don't place it around %

set /a var=%var% + 5   (Or simply set /a var += 5)

Test:

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

Output:

13150

Update

Another solution is to remove those commas with substitution:

set var=13,145
set /a var=%var:,=% + 5
Sign up to request clarification or add additional context in comments.

2 Comments

These values are generated by another bat file and I can't modify that file. Your solution is great, it resolves my problem. Thank you a lot.
Assuming the comma is not in the value, then you could simply use set /a var+=5. But if the comma is there, then yes, you must remove the comma first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.