I need to compare two strings ignoring whitespaces and newline characters, so the following strings should be equal:
"Initial directory structure.\r\n \r\n The directory tree has been changed"
"Initial directory structure.\n\nThe directory tree has been changed"
How can I implement it?
how about:
string stringOne = "ThE OlYmpics 2012!";
string stringTwo = "THe\r\n OlympiCs 2012!";
string fixedStringOne = Regex.Replace(stringOne, @"\s+", String.Empty);
string fixedStringTwo = Regex.Replace(stringTwo, @"\s+", String.Empty);
bool isEqual = String.Equals(fixedStringOne, fixedStringTwo,
StringComparison.OrdinalIgnoreCase);
Console.WriteLine(isEqual);
Console.Read();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With