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

    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


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

    • Proposed as answer by Mike Feng Thursday, August 9, 2012 3:58 AM
    • Marked as answer by Andreas Cui Sunday, August 12, 2012 6:13 AM
    • Edited by cheong00Editor Tuesday, June 16, 2015 1:27 AM
    Thursday, August 9, 2012 3:45 AM