471,348 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

valid culturename check

Hi all!

I'm working on a project where I have to check if a given string . a
valid culture name is.

Is there a way in .NET to do this very easy? The function I wrote for
this solution is not very elegant.

Can somebody help me out?
Jun 27 '08 #1
5 4598
al****************@gmail.com wrote:
I'm working on a project where I have to check if a given string . a
valid culture name is.

Is there a way in .NET to do this very easy? The function I wrote for
this solution is not very elegant.
CultureInfo.GetCultureInfo(name)
throws an exception if name is a not a supported CultureInfo.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
On 15 mei, 15:42, Martin Honnen <mahotr...@yahoo.dewrote:
alexandervanvee...@gmail.com wrote:
I'm working on a project where I have to check if a given string . a
valid culture name is.
Is there a way in .NET to do this very easy? The function I wrote for
this solution is not very elegant.

* *CultureInfo.GetCultureInfo(name)
throws an exception if name is a not a supported CultureInfo.

--

* * * * Martin Honnen --- MVP XML
* * * *http://JavaScript.FAQTs.com/
But that is not very elegant is it?
Jun 27 '08 #3
Maybe something like this?

private static string[] m_CultureNames;
public static bool IsCultureNameValid(string cultureNameToValidate)
{
if (m_CultureNames == null)
{
CultureInfo[] allCultures =
CultureInfo.GetCultures(CultureTypes.AllCultures);
m_CultureNames = new string[allCultures.Length];
for (int i = 0; i < allCultures.Length; i++)
{
CultureInfo ci = allCultures[i];
m_CultureNames[i] = ci.Name;
}
}

int index = Array.IndexOf<string>(m_CultureNames,
cultureNameToValidate);
return (index != m_CultureNames.GetLowerBound(0) - 1);
}
On May 15, 8:48*am, alexandervanvee...@gmail.com wrote:
On 15 mei, 15:42, Martin Honnen <mahotr...@yahoo.dewrote:
alexandervanvee...@gmail.com wrote:
I'm working on a project where I have to check if a given string . a
valid culture name is.
Is there a way in .NET to do this very easy? The function I wrote for
this solution is not very elegant.
* *CultureInfo.GetCultureInfo(name)
throws an exception if name is a not a supported CultureInfo.
--
* * * * Martin Honnen --- MVP XML
* * * *http://JavaScript.FAQTs.com/

But that is not very elegant is it?
Jun 27 '08 #4
On Thu, 15 May 2008 05:43:26 -0700 (PDT), al****************@gmail.com
wrote:
>Hi all!

I'm working on a project where I have to check if a given string . a
valid culture name is.

Is there a way in .NET to do this very easy? The function I wrote for
this solution is not very elegant.

Can somebody help me out?
If you can target .NET 3.5, you could try this:

using System;
using System.Linq;
using System.Globalization;

// [...]
bool IsValidCultureName(string cultureName)
{
return CultureInfo.GetCultures(CultureTypes.AllCultures)
.Any(ci =ci.Name == cultureName);
}

Regards,
Gilles.

Jun 27 '08 #5
Thnx this works fine for me!
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by John V | last post: by
7 posts views Thread by William Stacey [MVP] | last post: by
3 posts views Thread by Gonçalo Boléo | last post: by
3 posts views Thread by Chris | last post: by
reply views Thread by Rasheed | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.