LordSpigot LordSpigot - 1 year ago 131
C# Question

C# check if any letter in String A contains String B

I have a String (String1) with text "HELLO".

Now I want to check if String2 has ANY letter of String1.
If yes, I want to remove that letter in String2. How can I do that?

Answer Source

Try using Linq; to check if any characters of the firstString are in the secondString:

 bool result = firstString.Intersect(secondString).Any();

To remove firstString characters from the secondString:

 string result = string.Concat(secondString.Except(firstString)); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download