我有一个字符串列表,例如:
I have a list of strings such as:
约翰
John Doe
彼得·潘
.txt文件中.
我想做一个循环,检查某个名称是否存在.然而,如果我搜索"Peter",我不希望它是真的.并且只有"Peter Pan"存在.每行必须完全匹配.
I want to make a loop that checks if a certain name exists. However, I do not want it to be true if I search for "Peter" and only "Peter Pan" exists. Each line has to be a full match.
推荐答案哈哈,ep0的答案非常复杂!
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这是您的脚本:
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% }如果您的姓名以不同的顺序排列,则可能必须更改解析循环的定界符,或者使用regex而不是简单的比较.
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.
更多推荐
确定文件中是否存在字符串
发布评论