在DOS脚本中,没有定义用于查找字符串长度的长度函数,有一些自定义函数可用于相同的功能,以下是一个自定义函数的示例,用于查看字符串的长度。
@echo off set str = Hello World call :strLen str strlen echo String is %strlen% characters long exit /b :strLen setlocal enabledelayedexpansion :strLen_Loop if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop (endlocal & set %2=%len%) goto :eof
关于上述程序,需要记住的一些关键事项是-
在:strLen块中定义查找字符串长度的实际代码。
链接:https://www.learnfk.comhttps://www.learnfk.com/batch-script/batch-script-string-length.html
来源:LearnFk无涯教程网
字符串的长度保留在变量len中。
上面的命令产生以下输出。
11
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Tony Bai · Go语言第一课 -〔Tony Bai〕
PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕