LordSpigot LordSpigot - 3 months ago 24
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

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));