You should normalize each string by removing the characters that you don't want to compare and then you can perform a String.Equals
with a StringComparison
that ignores case.
Something like this:
string s1 = "HeLLo wOrld!";
string s2 = "Hello
WORLd!";
string normalized1 = Regex.Replace(s1, @"s", "");
string normalized2 = Regex.Replace(s2, @"s", "");
bool stringEquals = String.Equals(
normalized1,
normalized2,
StringComparison.OrdinalIgnoreCase);
Console.WriteLine(stringEquals);
Here Regex.Replace
is used first to remove all whitespace characters. The special case of both strings being null is not treated here but you can easily handle that case before performing the string normalization.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…