Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何批量测试变量的长度?_Batch File_String Length - Fatal编程技术网

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个字符长吗?