繁体   English   中英

Windows批处理文件字符串处理问题

[英]Windows Batch file String Manipulation Issues

我有一个批处理文件,该文件接收一个字符串“ this:EE notthis:that may:probably”,该字符串正在拆分,但是我需要操作拆分后的字符串,但不能。 任何帮助我指出正确方向的帮助将不胜感激。

脚本是:

:: Set the overrides string from the arguments, stripping quotes
SET overrridesString=%1
SET overrridesString=%overrridesString:"=%

FOR %%i in (%overrridesString%) do (
    SET tmpLine=%%i
    echo [DEBUG] Line is '%%i' and tmpLine is '%tmpLine%'
)

我虽然得到以下输出,这确实使我感到困惑:

[DEBUG] Line is 'this~EE' and tmpLine is 'may:probably'
[DEBUG] Line is 'notthis:that' and tmpLine is 'may:probably'
[DEBUG] Line is 'may:probably' and tmpLine is 'may:probably'

先感谢您

您需要延迟变量扩展和扩大tmpLine喜欢!tmpLine! ,因此其值将等于%%i

下面的代码应该可以完成您的期望:

SETLOCAL EnableDelayedExpansion

REM Set the overrides string from the arguments, stripping quotes
REM The '~' modifier removes surrounding '""' (see 'CALL /?')
SET overrridesString=%~1

FOR %%i in (%overrridesString%) do (
    SET tmpLine=%%i
    ECHO [DEBUG] Line is '%%i' and tmpLine is '!tmpLine!'
    REM The following line illustrates how to replace ':' by '$'
    ECHO [DEBUG] Manipulated tmpLine is '!tmpLine::=$!'
)
ENDLOCAL

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM