Home > Mobile >  C# string character is equal, but equal condition return false
C# string character is equal, but equal condition return false

Time:06-19

Here's part of the data from my SQL table:

SQL data

When I fetch data show me like below

c# show

But when I use equal condition, it returns false

enter image description here

I check ASCII code and I am confused because it is different.

this.NameOfComm :

enter image description here

"doc" :

enter image description here

CodePudding user response:

If you look very closely, you will note that, in your first screenshot, the DOC in the first line has a slightly different font than the one in the second line.

  • One of them contains the regular ASCII characters D O C , whereas
  • the other one contains the fullwidth forms from the Unicode block U FF00–FFEF. These are special forms of the Latin characters used to align nicely with Chinese/Japanese/Korean characters.

(In addition, the fullwidth form characters seem to be HTML encoded, but that might be an artifact of your analysis.)


You can use string.Normalize to "fix" this:

// prints DOC
Console.WriteLine("DOC".Normalize(NormalizationForm.FormKC));
  •  Tags:  
  • c#
  • Related