473,246 Members | 1,538 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,246 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 4760
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",...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.