none
"-" in mi-nz locale RRS feed

  • Question

  • Hi,

    I had a piece of code to separate locale to language and market, say from en-US to en and US. It worked fine until i see mi-nz locale. The code looks like this:

    class Program
        {
            static void Main(string[] args)
            {
                string market = "mi-nz";            
                System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(market);
                int index = market.IndexOf("-");
                Console.WriteLine(index);
                
            }
        }

    The output is 0.

    My question is what is special in "mi" language? If "-" is not found, I think it should return "-1".

    As i saw if i use IndexOf('-'), it returns 2.

    So "-" means something special in MI language?

    Thank you.

    Wednesday, August 8, 2012 1:09 AM

Answers

  • First, I want to point you to download the official sort weight table of Microsoft.

    Say you downloaded "Windows 7 and Windows server 2008 R2 Sorting Weight Table.txt" (because from this post, Māori support is apparently added in Win7), on line 246822, you can see the following:

    0x002d 0 0 0 0 ;Hyphen-minus

    See? This character carries zero sort weight.

    And because of explanation given here, searching it with IndexOf() will treat it as empty string, and tell you it's at the beginning of target string.

    EDIT: As for the reason of why it carries zero weight... The language uses Macrons to indicate the length of vowels. And because in traditional ASCII character set you don't have macron, hyphens are commonly used as replacement. Therefore when designing weight table for such language, characters that function like this are not given weight so they can be compared correctly.

    EDIT2: Note that you can have String.IndexOf(target, StringComparison.InvariantCulture) to workaround this behaviour.

    EDIT3: For why IndexOf('-') returns 2, from the remark of String.IndexOf(char) :

    This method performs an ordinal (culture-insensitive) search

    So the sort weight difference is irrelevent.

    EDIT on 2015/06/16: Fixed the links to www.siao2.com so they point to correct content.

    Thursday, August 9, 2012 3:45 AM
    Answerer