Problem with nested FOR-Loop and IF-Condition

混江龙づ霸主 提交于 2020-01-30 11:17:43

问题


I have some lines of text. Then I have a list with test-words. I like to look up each line of the text and check if one of the test-words appears in it. Beforehand this works well with a commands like these:

IF not "!stringToTest:%searchstring%=!"=="!stringToTest!"

However, now this seems to be more complicated as I have nested Loops?

I try to create a little MWE for my problem:

@echo off
setlocal enabledelayedexpansion
set /a counterPC=0
set "listPC=Win10,Motherboard,USB-Port,Core"
FOR %%G in (%listPC%) do (
    set PCsearchVal[!counterPC!]=%%G
    set /a counterPC+=1
)
set /a counterPC-=1
set "dummyline=Environment,1234,ZUIOP,Core"
FOR %%G in (%dummyline%) do (
    set "stringToTest=%%G"
    echo String to Test: !stringToTest!  
    FOR /l %%I in (0,1,%counterPC%) do ( 
        set "searchstring=!PCsearchVal[%%I]!"
        echo Test for this String: !searchstring!
        IF not "!stringToTest:%searchstring%=!"=="!stringToTest!" echo Searchstring is in String to Test
    )     
)
endlocal
pause

In this he alway enter the IF-Condition. I know that this can may be solved with FINDSTR however in all my other code I used the search-strategy liek above. There may be just a little mistake I oversee? Many thanks in advance-

来源:https://stackoverflow.com/questions/59197886/problem-with-nested-for-loop-and-if-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!