cultureinfo

Programmatic way to get all the available languages (in satellite assemblies)

南笙酒味 提交于 2019-11-26 18:49:37
I'm designing a multilingual application using .resx files. I have a few files like GlobalStrings.resx, GlobalStrings.es.resx, GlobalStrings.en.resx, etc. When I want to use this, I just need to set Thread.CurrentThread.CurrentCulture. The problem: I have a combobox with all the available languages, but I'm loading this manually: comboLanguage.Items.Add(CultureInfo.GetCultureInfo("en")); comboLanguage.Items.Add(CultureInfo.GetCultureInfo("es")); I've tried with cmbLanguage.Items.AddRange(CultureInfo.GetCultures(CultureTypes.UserCustomCulture)); without any success. Also tried with all the

Convert any currency string to double

泄露秘密 提交于 2019-11-26 17:42:39
I need to store multiple currencies in SQL server. I understand that SQL won't support all different types of currencies (unless I store it as a string, but I don't want to do that). My idea was to convert all the values from their currency format to a standard double and store that instead. Then just re-format based on the culture info when displaying. However, I have tried doing something like e.g. var cultureInfo = new System.Globalization.CultureInfo("en-US"); double plain = return Double.Parse("$20,000.00", cultureInfo); This doesn't ever seem to work it always throws a FormatException .

Find number of decimal places in decimal value regardless of culture

不问归期 提交于 2019-11-26 12:58:44
I'm wondering if there is a concise and accurate way to pull out the number of decimal places in a decimal value (as an int) that will be safe to use across different culture info? For example: 19.0 should return 1, 27.5999 should return 4, 19.12 should return 2, etc. I wrote a query that did a string split on a period to find decimal places: int priceDecimalPlaces = price.ToString().Split('.').Count() > 1 ? price.ToString().Split('.').ToList().ElementAt(1).Length : 0; But it occurs to me that this will only work in regions that use the '.' as a decimal separator and is therefore very brittle

Is Int32.ToString() culture-specific?

北城以北 提交于 2019-11-26 12:46:03
问题 I\'m running a beta version of ReSharper, and it\'s giving me warnings for the following code: int id; // ... DoSomethingWith(id.ToString()); The warning is on the id.ToString() call, and it\'s telling me \"Specify a culture in string conversion explicitly\". I understand the warning, and I know how to fix it -- just change the code to the much more unwieldy id.ToString(CultureInfo.InvariantCulture) . But my question is: is that necessary? I mean, obviously it\'s important to specify the

How to get current regional settings in C#?

余生颓废 提交于 2019-11-26 12:45:56
问题 Normally you can get it by writing something like CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; But this way you can only get CultureInfo which was configured at the moment application was launched and will not update if the setting have been changed afterwards. So, how to get CultureInfo currently configured in Control Panel -> Regional and Language Settings? 回答1: As @Christian proposed ClearCachedData is the method to use. But according to MSDN: The ClearCachedData

How can i convert English digits to Arabic digits?

…衆ロ難τιáo~ 提交于 2019-11-26 09:51:52
问题 I have this C# code for example DateTime.Now.ToString(\"MMMM dd, yyyy\"); Now the current thread is loading the Arabic culture. So the result is like this ???? 19, 2010 But i don\'t want the \'2010\' and the \'19\' to be in English (also known as Latin or West Arabic digits) - I want East Arabic numbers like \"٢\". I tried DateTime.Now.ToString(\"MMMM dd, yyyy\", CultureInfo.GetCultureInfo(\"ar-lb\")); gave the same result. So any idea? 回答1: Thy this workaround (just list all cultures you

How to translate CultureInfo language names

北战南征 提交于 2019-11-26 09:12:54
问题 I know of three ways to get a full language name of a CultureInfo object. CultureInfo.DisplayName CultureInfo.NativeName CultureInfo.EnglishName DisplayName gives the name in the installed .net language. NativeName gives the name in \'CultureInfos\' language. EnglishName gives the name in English (surprisingly...) So for CultureInfo de-DE this gives (on an English .net installation) German Deutsch German Now my question: Is there a way to ask for the language name of de-DE in another language

String sorting issue in C#

妖精的绣舞 提交于 2019-11-26 06:46:55
问题 I have List like this List<string> items = new List<string>(); items.Add(\"-\"); items.Add(\".\"); items.Add(\"a-\"); items.Add(\"a.\"); items.Add(\"a-a\"); items.Add(\"a.a\"); items.Sort(); string output = string.Empty; foreach (string s in items) { output += s + Environment.NewLine; } MessageBox.Show(output); The output is coming back as - . a- a. a.a a-a where as I am expecting the results as - . a- a. a-a a.a Any idea why \"a-a\" is not coming before \"a.a\" where as \"a-\" comes before \

Programmatic way to get all the available languages (in satellite assemblies)

試著忘記壹切 提交于 2019-11-26 06:36:47
问题 I\'m designing a multilingual application using .resx files. I have a few files like GlobalStrings.resx, GlobalStrings.es.resx, GlobalStrings.en.resx, etc. When I want to use this, I just need to set Thread.CurrentThread.CurrentCulture. The problem: I have a combobox with all the available languages, but I\'m loading this manually: comboLanguage.Items.Add(CultureInfo.GetCultureInfo(\"en\")); comboLanguage.Items.Add(CultureInfo.GetCultureInfo(\"es\")); I\'ve tried with cmbLanguage.Items

Convert any currency string to double

放肆的年华 提交于 2019-11-26 06:06:49
问题 I need to store multiple currencies in SQL server. I understand that SQL won\'t support all different types of currencies (unless I store it as a string, but I don\'t want to do that). My idea was to convert all the values from their currency format to a standard double and store that instead. Then just re-format based on the culture info when displaying. However, I have tried doing something like e.g. var cultureInfo = new System.Globalization.CultureInfo(\"en-US\"); double plain = return