如何检查我的input
-string是否包含我的字符串-list
中的任何字符串?我看了一些解决方案,但大多数都不是我想要的,而其他的则是Python和C ++。
你可以使用linq和string.Contains
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program
{
public static void Main()
{
var values = new List<string> { "some", "input", "values" };
var input1 = "this does not have any match";
Console.WriteLine("Input1 contains some match? " + values.Any(v => input1.Contains(v)));
var input2 = "this does have some match";
Console.WriteLine("Input2 contains some match? " + values.Any(v => input2.Contains(v)));
}
}