Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't IndexOf find the character N in combination with Y in hungarian culture?

Tags:

The IndexOf function called on a string returns -1, while there definitely is a match.

string sUpperName = "PROGRAMOZÁSI NYELVEK II. ADA EA+GY. (BSC 08 A)";
string sUpperSearchValue = "N";

sUpperName.IndexOf(sUpperSearchValue); // Returns -1

sUpperSearchValue = "NY";
sUpperName.IndexOf(sUpperSearchValue); // Returns 13

sUpperName[13]; // 78 'N'
sUpperSearchValue[0]; // 78 'N'
sUpperName[13] == sUpperSearchValue[0]; // true

Do you have any idea, why it is that it finds "NY" but not "N" by itself? If I search for every other letter in the string, it is able to find it, but not the "N". The same issue appears as well with lower case.

If I type " N" no match either, at " NY" it does.

Picture of this in console here

like image 226
Dark Avatar asked May 31 '14 13:05

Dark


1 Answers

In Hungarian .NET Culture the letter combination "ny" stands for a separate letter, so there is no "N" there, only "NY" in your example.

like image 190
Gábor Bakos Avatar answered Sep 23 '22 23:09

Gábor Bakos