C# string comparison ignoring spaces, carriage return or line breaks

前端 未结 10 953
执念已碎
执念已碎 2020-12-05 13:07

How can I compare 2 strings in C# ignoring the case, spaces and any line-breaks. I also need to check if both strings are null then they are marked as same.

Thanks!<

10条回答
  •  感情败类
    2020-12-05 13:22

    I would probably start by removing the characters you don't want to compare from the string before comparing. If performance is a concern, you might look at storing a version of each string with the characters already removed.

    Alternatively, you could write a compare routine that would skip over the characters you want to ignore. But that just seems like more work to me.

提交回复
热议问题