在Windows Batch中,如果我有一个变量(长度可以更改),例如:“ hello world!” 是否有可能“拆分”变量,以便每个字符都是其自己的变量,因此输出看起来像:
t1=h
t2=e
t3=l
etc.
任何帮助,将不胜感激。
使用此代码:
setlocal EnableDelayedExpansion
set str="hello world^!"
set tempstr=%str%
set count=0
:loop
if defined tempstr (
set tempstr=%tempstr:~1%
set /a count+=1
set /a pos=%count%-1
set t!count!=!str:~%pos%,1!
goto loop
)
:: check the generated variables
set t
要获取字符串中的第n个字符,请使用set char=%str:~n,1%
。
我希望这可以帮到你!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句