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

问题描述

这个问题类似于我之前的问题How to search for line with ConstructionTime(10); 在文件中并获取分配给变量的数字?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%

我可以10使用.ConstructionTime=(10);file.cfg

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

标签: batch-filecommand-prompt

解决方案


获得正确的标记和分隔符(不要关心,它会通过解析%丢失)

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

推荐阅读