- :StrLen
- setlocal enableextensions
- set "str=a%~2"
- set "str=%str:"=s%"
- set "str=%str:^^=s%"
- set "str=!str:%%=s!"
- set /a strlength=0
- :StrLen_1
- set /a strlength+=1
- if not "!str:~%strlength%,1!"=="" goto StrLen_1
- endlocal&set /a "%~1=%strlength%-1"
- goto :EOF
复制代码
如果作为库函数的话,我觉得LS的代码不行,因为你不知道变量可能的长度,就把for设定在10000了,缺乏通用性
如果要完全通用的话,就要把10000改成2^31-1,就是2147483647
改完之后,执行时间就增长了。。。 |