C#字符串不包含可能吗? [英] C# string does not contain possible?

查看:239
本文介绍了C#字符串不包含可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我要做的。我有一个可读取html的搜寻器,我想知道它何时不包含两个字符串。例如。

This is what I have going on. I have a crawler that reads html, and i'm looking to know when it does not contain two strings. For example.

string firstString = "pineapple"
string secondString = "mango"

string compareString = "The wheels on the bus go round and round"

所以基本上我想知道当第一个字符串和第二个字符串不在compareString中时。

So basically I want to know when the first string and second string are not in the compareString.

感谢所有帮助!

推荐答案

您应该将所有单词放入某种集合或列表中,然后这样称呼它:

You should put all your words into some kind of Collection or List and then call it like this:

var searchFor = new List<string>();
searchFor.Add("pineapple");
searchFor.Add("mango");

bool containsAnySearchString = searchFor.Any(word => compareString.Contains(word));

如果您需要进行案例或与文化无关的搜索,则应这样称呼:

If you need to make a case or culture independent search you should call it like this:

bool containsAnySearchString = 
   searchFor.Any(word => compareString.IndexOf
     (word, StringComparison.InvariantCultureIgnoreCase >= 0);

这篇关于C#字符串不包含可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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