我正在逐行读取一个特定字符串的文本文件,然后将每个字符串存储在array.now中我必须将每个数组元素与特定的字符串进行比较。我已尝试使用以下代码...... ...
setlocal enabledelayedexpansion enableextensions
for /F "tokens=2,3 delims= " %%a in ('findstr "associationMaxRtx maxIncomingStream maxOutgoingStream initialAdRecWin maxUserdataSize mBuffer nThreshold PathMaxRtx maxInitialRtrAtt minimumRto maximumRto initialRto rtoAlphaIndex tSack" C:\Users\ephajin\logs.txt') do (
set /A count+=1
set vartmp1=%%a
set vartmp2=%%b
set "array[!count!]="%%a %%b""
)
(FOR /L %%a IN (1,1,%count%) DO SET "result=!result! !array[%%a]!"
if %result% == "associationMaxRtx 8"(
echo no need of modification) > result.txt
但在结果文件中我收到以下输入:
get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17 maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack
在结果文件中所有数组元素都显示在一行中为什么我不知道,但实际上如下所示:
array[0]=get .
array[1]=associationMaxRtx 8
array[2]=associationMaxRtx 8
等等。我必须将每个数组元素与特定字符串进行比较,例如array [1] =" associationMaxRtx 8",然后打印一条消息。如何做到这一点请帮帮我
答案 0 :(得分:0)
我认为上面缺少一段代码,但为了删除生成的SET
语句中的额外引号,这将有效:
(FOR /f "tokens=1* delims==" %%a IN ('set array[') DO SET "result=%%~b"
ECHO "%result%" ) > result.txt
在~
之前添加b
符号(使其成为%%~b
),围绕%%b
展开的前导和尾随引号。
这将产生(例如):
SET" result = rtoAlphaIndex 3"