Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robertmuehsig/254bf575dc1cdb85f50e87fb6b3d4b92 to your computer and use it in GitHub Desktop.
Save robertmuehsig/254bf575dc1cdb85f50e87fb6b3d4b92 to your computer and use it in GitHub Desktop.
de-CH separator
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SwissCultureParsing
{
class Program
{
static void Main(string[] args)
{
var culture = new CultureInfo("de-CH");
try
{
Console.WriteLine("de-CH Group Separator");
Console.WriteLine($"{culture.NumberFormat.CurrencyGroupSeparator} - CharCode: {(int)char.Parse(culture.NumberFormat.CurrencyGroupSeparator)}");
Console.WriteLine($"{culture.NumberFormat.NumberGroupSeparator} - CharCode: {(int)char.Parse(culture.NumberFormat.NumberGroupSeparator)}");
Console.WriteLine($"Sane way would be ' - CharCode: {(int)char.Parse("'")}");
Console.WriteLine(double.TryParse("1'000", NumberStyles.Any, culture, out _));
Console.WriteLine(":(");
Console.WriteLine("’");
Console.WriteLine((int)'’');
Console.WriteLine(double.TryParse("1'000.00", NumberStyles.Any, culture, out _));
Console.WriteLine(double.TryParse("1'000", NumberStyles.Number, culture, out _));
Console.WriteLine(double.TryParse("1'000", NumberStyles.Currency, culture, out _));
Console.WriteLine(double.TryParse("1" + culture.NumberFormat.CurrencyGroupSeparator + "000", NumberStyles.Currency, culture, out _));
Console.WriteLine(double.TryParse("1" + culture.NumberFormat.NumberGroupSeparator + "000", NumberStyles.Currency, culture, out _));
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment