使用C#来检查是否字符串包含字符串数组字符串 [英] Using C# to check if string contains a string in string array
本文介绍了使用C#来检查是否字符串包含字符串数组字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用C#来检查,如果一个字符串值,包含字符串数组一个字。例如,
I want to use C# to check if a string value contains a word in a string array. For example,
string stringToCheck = "text1text2text3";
string[] stringArray = ("text1", etc... )
if(stringToCheck.contains stringArray( //one of the items?
{
}
我如何检查是否为stringToCheck字符串值包含数组中的一个词吗?
How can I check if the string value for 'stringToCheck' contains a word in the array?
推荐答案
这里是你如何能做到这一点:
here is how you can do it:
string stringToCheck = "text1";
string[] stringArray = { "text1", "testtest", "test1test2", "test2text1" };
foreach (string x in stringArray)
{
if (x.Contains(stringToCheck))
{
// Process...
}
}
这篇关于使用C#来检查是否字符串包含字符串数组字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文