2

In Latvian culture lv-LV there are special characters like 'ā', 'ī', 'ģ' etc. Is there any built-in way, where following code returns true ?

var nameLv = "Jevģeņijs";

var nameEng = "Jevgenijs";

nameLv.Equals(nameEng, StringComparison.InvariantCultureIgnoreCase);

1 Answers1

2

Here's a solution that applies this answer to your code.

public static void Main()
{
    var nameLv = "Jevģeņijs";
    var nameEng = "Jevgenijs";

    var result = IsEquivalent(nameLv, nameEng);  // returns True
}

public static bool IsEquivalent(string latvian, string english)
{
    return english ==
        Encoding.UTF8.GetString(Encoding.GetEncoding("ISO-8859-8").GetBytes(latvian));
}

I can't say whether this is the most robust method or will work given any particular strings, but tested with your input it seems to work fine.

There are quite a few other solutions in that same thread that you might want to check out too.

Community
  • 1
  • 1
Grant Winney
  • 65,241
  • 13
  • 115
  • 165