Monday, May 16, 2011

Two exactly same strings fail while comparison in c# .Net

I had an input field which had a space , some browsers were giving different hex for space in these input fields.

Finally I found , a space may not be a space there are as much as 25 different representations for space in Hex.

.Replace((char)0xA0, ' ') worked but better way is using .Normalize(System.Text.NormalizationForm.FormKC)

Reference : http://msdn.microsoft.com/en-us/library/ebza6ck1(v=vs.80).aspx
and http://msdn.microsoft.com/en-us/library/system.text.normalizationform(v=vs.80).aspx

2 comments:

  1. Difference between :
    System.Text.NormalizationForm.FormC
    System.Text.NormalizationForm.FormD
    System.Text.NormalizationForm.FormKC
    System.Text.NormalizationForm.FormKD

    Available here :
    http://www.unicode.org/reports/tr15/#Norm_Forms

    ReplyDelete
  2. Normalization in javascript :
    https://github.com/patch/unicode-programming/blob/master/normalization/javascript.md

    ReplyDelete