Tinia
Tinia

Reputation: 205

IndexOf bug when string contains 'AA'

I've run into a strange problem. I have a string with a value containing 'AA'. I'm trying to find IndexOf the first accouring A. When I ask if the string Contains("A") it returns true. When using IndexOf("A") I keeps getting the default value -1! (se the picture below)

enter image description here

So far i tested there is only a problem with 'A' and 'a'. When putting 3 a's in the string I get the index of number 3, as if the first two doesn't exsist.

enter image description here

When adding an extra a to the string, I get the default value -1 again.

enter image description here

I don't know what is causing this, I have a suspision that it's somehow connected to some langauge setting. I'm from denmark, and the use of the letters aa is a synonym for å.

Have anyone else experinced a simular problem or have a suggestion how to avoid it?

System information:

Windows 7 Ultimate (English)

Visual Studio 10 Premium

Upvotes: 3

Views: 262

Answers (2)

Smokefoot
Smokefoot

Reputation: 1805

Hmmm I have tried the same now. It works...

    static void XYZ()
    {
        string a = "aaa";
        string b = "AAA";

        if(a.Contains("a"))
        {
            Console.WriteLine(a.IndexOf("a"));
        }
        if(b.Contains("A"))
        {
            Console.WriteLine(b.IndexOf("A"));
        }
    }

But wouldn't it be the best to seach for a "aa" and "AA"? I can speak danish and I know that there are single a's too ;-)

Upvotes: 0

Olaf
Olaf

Reputation: 10247

'aa' is handled as an entity if the culture is da-DK. The question is sort of a duplicate, see String StartsWith() issue with Danish text.

Upvotes: 2

Related Questions