如何检查我的input
字符串是否在我的字符串list
中包含任何字符串?
我查找了一些解决方案,但大多数不是我想要的,而其他解决方案则是使用Python和C ++。
答案 0 :(得分:1)
您可以使用linq和string。包含
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)));
}
}