且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中的字符串数组中搜索子字符串

更新时间:2021-09-03 04:53:55

如果您需要的是关于lineVar是否存在于数组的任何字符串中的布尔型真/假答案,请使用以下方法:>

If all you need is a bool true/false answer as to whether the lineVar exists in any of the strings in the array, use this:

 arrayStrings.Any(s => s.Contains(lineVar));

如果您需要索引,那会有点棘手,因为它可以出现在数组的多个项目中.如果您不想要布尔,可以解释您的需求吗?

If you need an index, that's a bit trickier, as it can occur in multiple items of the array. If you aren't looking for a bool, can you explain what you need?