473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 4776
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: John V | last post by:
What kind of regular expression pattern is needed to check if URL is valid? It's enought if most of cases are covered. I have PHP 4.x. Br
16
by: siliconmike | last post by:
Hi, I'm looking for a reliable script that would connect to a host and somehow determine whether an email address is valid. since getmxrr() only gets the mx records.. Links/pointers ? Mike
7
by: William Stacey [MVP] | last post by:
Given a day of the month (<=31) how to calculate if that day is valid for all months up to some end date or DateTime.MaxValue? TIA -- William Stacey, MVP
3
by: Gonçalo Boléo | last post by:
Is there any way to check if a string is valid URL? thanks, Gonçalo Boléo
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
0
by: Rasheed | last post by:
Hi All, Could any body help me. Regarding how to check a URL is Valid or Invalid. I am using Four functions to check the same. 1) hConnect = WinHttpConnect( hSession, "www.google.co.in",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.