Determine if string exists in file

前端 未结 2 1668
长情又很酷
长情又很酷 2021-01-28 22:35

I have a list of strings such as:

John

John Doe

Peter Pan

in a .txt file.

I want to make a loop that checks if a ce

2条回答
  •  情歌与酒
    2021-01-28 23:06

    Ha ha, ep0's answer is very sophisticated!

    However, you want to use a parsing loop something like this (this example expects that your names are separated by carriage returns). Consider that you have a text file with contents arranged like this:

    John
    Harry
    Bob
    Joe
    

    Here is your script:

    fileread, thistext, %whatfile%  ;get the text from the file into a variable
    ;Now, loop through each line and see if it matches your results:
    
    loop, parse, thistext, `r`n, `r`n
    {
      if(a_loopfield = "John")
         msgbox, Hey! It's John!
      else
         msgbox, No, it's %a_loopfield%
    }
    

    If your names are arranged in a different order, you might have to either change the delimiter for the parsing loop, or use regex instead of just a simple comparison.

提交回复
热议问题