C#, CRM, Microsoft CRM Dynamics

String.Equals returning false even for same strings

If you are startled by seeing String.Equals returning false for exactly similar looking strings, this is what you need to do:

  1. Check if both strings have equal lengths, if not return
  2. Check Trimmed versions of both strings, there maybe extra white-spaces that get unnoticed.
  3. Finally if both lengths are equal and trimmed versions look exactly the same, the issue could be the encoding of the spaces in the 2 strings as they maybe be coming from different sources. In this case, use the following code to correct the encoding:

image 

Using regex, I have just replaced the unicode equivalent of space with a space.

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s