locked
Test for valid language-region string RRS feed

  • Question

  • User-1029435529 posted
    <color="#000000;width:500px;">Say that my code receives a five letter string, with a hypen as its middle character (such as "en-au"). Is it possible to test whether this is a valid language-region identifier without trying to instantiate a new CultureInfo object using that string? Currently, I must do something similar to: System.Globalization.CultureInfo culture = null; string possibleCulture = "en-au"; try { culture = new System.Globalization.CultureInfo(possibleCulture); } catch { } if (culture != null) { // only NOW do I know whether the string is a valid language-region identifier. }Is there a crisper way to test whether the string is a valid language-region identifier? My look at the documentation suggests that the answer is no. However, I want to see whether anyone has approached this differently.</color>
    Friday, December 10, 2004 11:07 PM

All replies

  • User-158764254 posted
    I posted virtually the exact same question a number of months ago. The only response i received was to use the try/catch. Thats pretty much where i left it as i already had the try/catch in place. I suppose, you could keep a list of bad cultures around at application scope so you dont keep repeating what you already know will fail. i.e. If KnownBadCultures.Contains(possibleCulture) Then...
    Saturday, December 11, 2004 2:44 PM
  • User-1029435529 posted
    <color="#6633cc;width:550px;">> Thats pretty much where i left it as i already had the try/catch in place.</color> <color="#000000;width:550px;">Yeah, I too have it up and working with two try/catch blocks ... one to try the submitted culture; a second to try the app's default culture; otherwise it falls to the InvariantCulture. It's the two try/catch blocks that I was hoping to avoid. The KnownBadCulture is an idea. I'll think about it. Thanks for your reply.</color>
    Saturday, December 11, 2004 11:04 PM