我基本上需要测试一个变量在批处理文件中的长度。例子:
@echo off
set /p someVar=""
//some code to figure out how long it is
cls
echo someVar is %length% characters long.
pause
exit
所以如果我输入
Batch files
它会说
someVar is 10 characters long.
我基本上需要测试一个变量在批处理文件中的长度。例子:
@echo off
set /p someVar=""
//some code to figure out how long it is
cls
echo someVar is %length% characters long.
pause
exit
所以如果我输入
Batch files
它会说
someVar is 10 characters long.
根据@minitech 提供的链接,这是一个应该可以工作的脚本:
@echo off
set /p someVar=""
::some code to figure out how long it is
::Start by writing the file to a temp file
echo %someVar%>"%temp%\tmp.txt"
:: get the files size in bytes and subtract 3 for the trailing space and newline and delete the temp file
for %%a in (%temp%\tmp.txt) do set /a length=%%~za & set /a length -=3 & del "%temp%\tmp.txt"
cls
echo someVar is %length% characters long.
pause
exit