如何使用 Effective("flyer", 100%); 搜索行;在文件中并获取分配给变量的数字?

How to search for line with Effective("flyer", 100%); in a file and get the number assigned to a variable?

这个问题类似于我之前的问题,Mofi 使用以下代码解决了这个问题:

@echo off
set "ConstrutionTime="
for /F "tokens=2 delims=()" %%I in ('%SystemRoot%\System32\find.exe /I "constructiontime" file.cfg') do set "ConstrutionTime=%%I"
if defined ConstrutionTime echo The construction time is: %ConstrutionTime%

我可以使用 file.cfg.

中的代码从 ConstructionTime=(10); 的行中获取数字 10

但是 Effective("flyer", 100%); 呢?
如何从中获取 100 并将其分配给环境变量?

获取正确的标记和分隔符(不关心 %,它会被 parsing 丢失)

@echo off
set "string=Effective("flyer", 100%);"
for /f "tokens=2 delims=) " %%a in ("%string%") do set "number=%%a"
set number

行示例的解决方案是:

@echo off
set "Effective="
for /F "tokens=2 delims=%%) " %%I in ('%SystemRoot%\System32\find.exe /I "Effective" file.cfg') do set "Effective=%%I"
if defined Effective echo The effective value is: %Effective%

此解决方案要求双引号中的字符串不包含 space 字符,也没有 space 字符留给感兴趣的值 space 字符。

另一个解决方案是:

@echo off
set "Effective="
for /F "tokens=2 delims=%%)," %%I in ('%SystemRoot%\System32\find.exe /I "Effective" file.cfg') do for /F %%J in ("%%I") do set "Effective=%%J"
if defined Effective echo The effective value is: %Effective%

此解决方案也适用于逗号后没有 space 的行,以及在感兴趣的数字左侧有一个或多个 space 的行。但引用的字符串不能包含逗号。

第三种解决方案也适用于多个 space 和逗号留给感兴趣的数字。

@echo off
set "Effective="
for /F tokens^=3^ delims^=^" %%I in ('%SystemRoot%\System32\find.exe /I "Effective" file.cfg') do for /F "delims=%%), " %%J in ("%%I") do set "Effective=%%J"
if defined Effective echo The effective value is: %Effective%