简体   繁体   中英

Is there any string.Contains or related method

I am writing a code to if characters from 1 string are present in another string. I used string.Contains but its not solving my case

string str = "abc";
string str2 = "ac";

if(str.Contains(str2))
{
    Console.WriteLine("true");
}

I want result to be true. but its not returning true

How about

string str = "abc";
string str2 = "ac";

bool containsAll = !str2.Except(str).Any();

because

在此处输入图片说明

I am writing a code to if characters from 1 string are present in another string.

I guess you want to check: " if All characters from 1 string are present in another string."

string str = "abc";
string str2 = "ac";

Console.WriteLine(str2.All(x => str.Contains(x)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM