tomlev

Convert number to native digits

Aug 20th, 2011
251
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static string ToNativeDigits(this string text, CultureInfo culture = null)
  2.     {
  3.         culture = culture ?? CultureInfo.CurrentCulture;
  4.         var nativeDigits = culture.NumberFormat.NativeDigits;
  5.         StringBuilder sb = new StringBuilder();
  6.         for (int i = 0; i < text.Length; i++)
  7.         {
  8.             char c = text[i];
  9.             if (c >= '0' && c <= '9')
  10.             {
  11.                 int v = (int)(c - '0');
  12.                 string nc = nativeDigits[v];
  13.                 sb.Append(nc);
  14.             }
  15.             else
  16.             {
  17.                 sb.Append(c);
  18.             }
  19.         }
  20.         return sb.ToString();
  21.     }
RAW Paste Data