純批:
for /f "delims==," %%A in ("%input:*test/time (ms)=%) do echo %%A
搜索和替換內IN子句查找的test/time (ms)
第一次出現,並從原來的字符串用什麼搜索字符串的結束的開始取代。 FOR/F然後解析出100個使用分隔符=
和,
。
在%input%
的值內包含引號會導致IN()子句看起來很奇怪,並且沒有可見的結束引號。
它看起來與延遲擴展更好:
setlocal enableDelayedExpansion
for /f "delims==," %%A in ("!input:*test/time (ms)=!") do echo %%A
我寧願保持封閉的報價我的變量值,並明確根據需要將它們添加到我的代碼。這使得正常的擴展版本看起來更自然(延遲擴展版本保持相同):
set "input=test/ing=123, hello/world=321, test/time (ms)=100, test/status=0"
for /f "delims==," %%A in ("%input:*test/time (ms)=%") do echo %%A
批量使用JScript的幫助
如果你有我hybrid JScript/batch REPL.BAT utility,那麼你可以使用正則表達式是非常具體的在您解析:
call repl ".*test/time \(ms\)=(.*?),.*" $1 sa input
要在變量得到值:
set "val="
for /f "delims=" %%A in ('repl ".*test/time \(ms\)=(.*?),.*" $1 sa input') do set "val=%%A"
請注意,IN()子句中不需要CALL。使用管道時也不需要。
找到單個'perl.exe'可執行文件(xampp for windows有一個) –
對不起。我不明白你的意思。它如何幫助將腳本更改爲批處理文件格式? – Sakura
使用Perl你不必做任何轉換;) –