确定文件中是否存在字符串 [英] Determine if string exists in file

查看:74
本文介绍了确定文件中是否存在字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串列表,例如:

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.

这篇关于确定文件中是否存在字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆