[英]Convert a string to integer in a batch file
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
. 但是结果是
13+5
,而不是13145+5
。
How can I delete this "," from my string? 如何从字符串中删除此“,”?
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
Another solution is to remove those commas with substitution: 另一个解决方案是用替换删除那些逗号:
set var=13,145
set /a var=%var:,=% + 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.