Collection key regional settings german umlaute

Hi newsgroup,

greetings from Germany. I've a simple vb.net 2005 code-snippet:

Dim x As New Collection

x.Add(0, "Muller")

x.Add(0, "Mueller")

I found out, that sometimes the snippet runs (as compiled exe) without any problems, sometimes not.

Adding an item with the key Mueller, when the key Muller exists, may raise an exception. It depends on the regional settings (German Windows XP Regions- und Sprachoptionen).

The sort-option Telefonbuch (DIN) raises the error, Worterbuch doesn't.

Is this behaviour a bug I think so, because a string should not be converted into a system string using a special sort-setting before it is used in a collection key.

What do you think about it

Sorry, but I don't know the english words for the options.

Thank you for your answers!



Answer this question

Collection key regional settings german umlaute

  • efratian

    Dim x As New System.Collections.Generic.SortedList(Of String, String)(StringComparer.InvariantCulture)

    The InvariantCulture solves my problem. The sort setting from the operating system is ignored.

    Thank you very much, Johan and Stephen!

    Migeold.

  • ParkerMelvin

    Hi Johan,

    thank you very much for your help!

    I am using the VisualBasic.Collection class.

    Please, could you give me an hint how I can pass the StringComparer in the SortedList.

    SortedList.Comparer is readonly.

    Thanks, migeold.


  • jwagner20

    When you create the list you can specify the stringComparer: e.g.

    Dim L As New SortedList(Of String, String)(StringComparer.CurrentCultureIgnoreCase)

    (the above should be on a single line...)



  • gooon

    Are you using the Microsoft.VisualBasic.Collection class If so, My personal recommendation that you switch to a collection class that gives you a bit more control over what you are doing. VB6 was greate in many ways, but it wasn't always easy to work with culture-aware thingies. The .NET Framework is *much* better at this.

    Try the System.Collections.Generic.SortedList class . You can pass in the StringComparer that you want to control what strings are supposed to be treated as "equal".

    Best regards,
    Johan Stenberg



  • Collection key regional settings german umlaute