开发者

What is this char? 65279 ''

开发者 https://www.devze.com 2023-03-21 23:12 出处:网络
I have two strings. one is \"\\\"\" and the other is \"\\\"\" I think that they are same. However, String.Compare says they are different.

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 = "\"";
strin开发者_JAVA技巧g 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?


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


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.


You can remove it with:

Trim(new char[]{'\uFEFF','\u200B'});


If you are reading from a file you have opened in notepad, it may have added it as it is one of several programs notorious for doing so.


It is byte order mark(BOM). A BOM is a special marker at the beginning of a file that indicates the byte order of the text data in the file.

We can remove the BOM in JavaScript using the following code

    function removeBOM(jsonString) {
        if (jsonString.charCodeAt(0) === 0xfeff) {
            jsonString = jsonString.slice(1);
        } 
        return jsonString;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消