110,535
社区成员
发帖
与我相关
我的任务
分享
string a = "abcde";
string b = "affa";
IEnumerable<char> temp = a.Intersect(b);
bool isExist = b.Except(temp).Count() == 0;
// even better :)
static bool ContainsAllChars(string str, string chars)
{
return new HashSet<char>(chars).IsSubsetOf(str);
}
static bool ContainsAllChars(string str, string chars)
{
var distinctChars = chars.Distinct().ToList();
return str.Intersect(distinctChars).Count() == distinctChars.Count;
}
static void Main(string[] args)
{
bool b = ContainsAllChars("abcde", "aecc"); // true
}