Is this strange IndexOf behaviour intended?

Viewed 51

I was investigating a bug and found that a hard coded string defined with a slightly different double quotes (" vs ") produces the following behavior when calling the IndexOf method:

Console.WriteLine(":::".IndexOf(":", 2));

Console.WriteLine(":::ؘ".IndexOf(":", 2));

The output will be:

2
-1

(run it here)

After further investigation, it seems that using the different double quotes character when defining the string causes it to have Length "4" instead of "3". The following code:

Console.WriteLine((int)":::ؘ".Length);
Console.WriteLine((int)":::ؘ"[0]);
Console.WriteLine((int)":::ؘ"[1]);
Console.WriteLine((int)":::ؘ"[2]);
Console.WriteLine((int)":::ؘ"[3]);

Outputs:

4
58
58
58
1560

(run it here)

Still, I don't understand why the IndexOf would fail to find that last occurence of the colon character.

Is this behavior intended?

0 Answers
Related