批處理命令For——分割字符串
windows下批處理命令分割字符串代碼
@echo off
set str="aa_bb_cc"
:GOON
for /f "delims=_, tokens=1,*" %%i in (%str%) do (
echo %%i %%j
set str="%%j"
goto GOON
)
輸出結(jié)果
aa bb_cc
bb cc
cc
delims字符串中的分割字符,不使用delims時(shí),默認(rèn)分割字符是空格和tab字符
tokens提取每行指定列,其中%%i, %%j就是具體的提取內(nèi)容。更多內(nèi)容參見(jiàn)FOR參數(shù)/F之tokens詳解
|