Format string by CultureInfo

Use the Currency standard format string along with the string.Format method that takes a format provider: string.Format(new System.Globalization.CultureInfo(“en-GB”), “{0:C}”, amount) The CultureInfo can act as a format provider and will also get you the correct currency symbol for the culture. Your example would then read (spaced for readability): <td style=”text-align:center”> <%# string.Format(new System.Globalization.CultureInfo(“en-GB”), “{0:C}”, Convert.ToSingle(Eval(“tourOurPrice”)) … Read more

Replace German characters (umlauts, accents) with english equivalents

The process is known as removing “diacritics” – see Removing diacritics (accents) from strings which uses the following code: public static String RemoveDiacritics(String s) { String normalizedString = s.Normalize(NormalizationForm.FormD); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < normalizedString.Length; i++) { Char c = normalizedString[i]; if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark) stringBuilder.Append(c); } return … Read more

Culture invariant Decimal.TryParse()

In fact CultureInfo.InvariantCulture can be used here. The parameter expects IFormatProvider, an interface that CultureInfo implements. But InvariantCulture is invariant in the sense that it does not vary with the user’s settings. In fact, there is no culture that accepts either , or . as decimal separator – they are all one or the other. … Read more

.NET (3.5) formats times using dots instead of colons as TimeSeparator for it-IT culture?

I can guarantee in Italy we use colons to separate hour and minute digits, and we use the 24-hour format. Wikipedia is correct (at least this time). Your problem is likely that you’re not setting the Thread’s UI culture. Something like this should work: Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(“it-IT”);

Is Int32.ToString() culture-specific?

The Operating System allows to change the negative sign for numbers. Control panel -> Language and regional settings -> Additional settings -> Negative sign So, current culture could have overridden the negative sign. In this case you need to respect the regional settings, this is the reason of the warning. You can also change the … Read more

Change Language in C#

To select a whole new culture, set the CurrentThread.CurrentCulture to a new culture, e.g. to set to French: System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(“fr-FR”); System.Threading.Thread.CurrentThread.CurrentCulture = ci; You can find a list of the predefined CultureInfo names here and here. If you want to change certain aspects of the default culture, you can grab the current … Read more

How to get current regional settings in C#?

As @Christian proposed ClearCachedData is the method to use. But according to MSDN: The ClearCachedData method does not refresh the information in the Thread.CurrentCulture property for existing threads So you will need to first call the function and then start a new thread. In this new thread you can use the CurrentCulture to obtain the … Read more