Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this char? 65279 ''

Tags:

c#

char

I have two strings.

one is "\""

and the other is "\""

I think that they are same.

However, String.Compare says they are different.

This is very strange.

Here's my code:

string b = "\"";
string c = "\"";

if (string.Compare(b, c) == 0)
{
    Console.WriteLine("Good");
}

if (c.StartsWith("\""))
{
    Console.WriteLine("C");
}

if (b.StartsWith("\""))
{
    Console.WriteLine("B");
}

I expected that it may print "GoodCB".

However, it only prints "B".

In my debugger, c[0] is 65279 '' and c[1] is 34 '"'. and b[0] is '"'.

But I don't know what 65279 '' is.

Is it an empty character?

like image 301
장선민 Avatar asked Jul 22 '11 01:07

장선민


3 Answers

It's a zero-width no-break space.
It's more commonly used as a byte-order mark (BOM).

like image 113
SLaks Avatar answered Nov 17 '22 11:11

SLaks


If you are using Notepad++, try converting to UTF-8 (no BOM), and also make sure ALL your files in the project are the same file system format.

like image 36
kurdtpage Avatar answered Nov 17 '22 10:11

kurdtpage


You can remove it with:

Trim(new char[]{'\uFEFF','\u200B'});
like image 5
Victor Avatar answered Nov 17 '22 10:11

Victor