Batch file 如何批量测试变量的长度?
我基本上需要测试变量在批处理文件中的时间长度。例如:Batch file 如何批量测试变量的长度?,batch-file,string-length,Batch File,String Length,我基本上需要测试变量在批处理文件中的时间长度。例如: @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 o
@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
我不是一个批处理脚本编写者,但谷歌给出了这样一个结论:字符串“batchfiles”不是11个字符长吗?