3

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

Tinia
  • 205
  • 3
  • 9

2 Answers2

2

'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.

Community
  • 1
  • 1
Olaf
  • 10,049
  • 8
  • 38
  • 54
0

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 ;-)

Smokefoot
  • 1,695
  • 2
  • 10
  • 13
  • The context of the original accourance of the problem is in a application depending on dynamic values, so searching for 'aa' would not solve the problem. The question is asked with hope of avoiding the cause, to prevent the problem from accouring other places in the application. – Tinia Aug 16 '11 at 09:43