确定文件中是否存在字符串

编程入门 行业动态 更新时间:2024-10-28 16:28:34
本文介绍了确定文件中是否存在字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

确定文件中是否存在字符串

本文发布于:2023-10-29 20:41:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   是否存在   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!