1

试图仅隔离 .BAT 变量中包含的字符串的一部分。

字符串变量!原始!包含以下内容:

v2.30|Action=Allow|Active=FALSE|Dir=In|Profile=Domain|Profile=Private|Name=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/PackageDisplayName}|Desc=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/ProductDescription}|LUOwn=S-1-5-21-1502285707-838241421-2811185785-1001|AppPkgId=S-1-15-2-1861897761-1695161497-2927542615-642690995-327840285-2659745135-2630312742|EmbedCtxt=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/PackageDisplayName}|Platform=2:6:2|Platform2=GTEQ|

我正在尝试将其解析为单词“ Name= ”之后的字符序列。

以下 For 循环返回:系统找不到文件 v2.30|Action。

FOR /F "tokens=* delims=" %%h in (!Original! ^| Findstr "Name=") do (ECHO %%h)

我究竟做错了什么?为什么它只读取!Original的前一小部分内容!?

赞赏...

4

1 回答 1

0

试试这个(另存为.bat):

@if (@X)==(@Y) @end /* JScript comment
    @echo off

    set "string=v2.30|Action=Allow|Active=FALSE|Dir=In|Profile=Domain|Profile=Private|Name=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/PackageDisplayName}|Desc=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/ProductDescription}|LUOwn=S-1-5-21-1502285707-838241421-2811185785-1001|AppPkgId=S-1-15-2-1861897761-1695161497-2927542615-642690995-327840285-2659745135-2630312742|EmbedCtxt=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/PackageDisplayName}|Platform=2:6:2|Platform2=GTEQ|"
    set "splitBy=|"

    for /f "tokens=* delims=" %%a in ('cscript //E:JScript //nologo "%~f0"  "%string%" "%splitBy%"') do (
        set "%%~a" 2>nul
    )
    echo %Name%
    exit /b %errorlevel%

@if (@X)==(@Y) @end JScript comment */

var string=WScript.Arguments.Item(0);
var splitBy=WScript.Arguments.Item(1);

var i;
for (i = 0; i < string.split(splitBy).length; i++) {
  WScript.Echo(string.split(splitBy)[i]);
}

仅批处理语法解决方案:

@echo off
setlocal EnableDelayedExpansion

@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%


set "string=v2.30|Action=Allow|Active=FALSE|Dir=In|Profile=Domain|Profile=Private|Name=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/PackageDisplayName}|Desc=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/ProductDescription}|LUOwn=S-1-5-21-1502285707-838241421-2811185785-1001|AppPkgId=S-1-15-2-1861897761-1695161497-2927542615-642690995-327840285-2659745135-2630312742|EmbedCtxt=@{Microsoft.Windows.Cortana_1.13.0.18362_neutral_neutral_cw5n1h2txyewy?ms-resource://Microsoft.Windows.Cortana/resources/PackageDisplayName}|Platform=2:6:2|Platform2=GTEQ|"

setlocal enableDelayedExpansion
echo !string:^|=%NL%! >#
for /f "tokens=* delims=" %%a in (#) do (
    set "%%~a" >nul 2>&1
)

echo %NAME%
del /q #
于 2020-03-27T16:00:36.130 回答