Skip to content

Instantly share code, notes, and snippets.

@codehaks
Created January 27, 2020 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehaks/492c4464ac8d2e80e2f0f51df36b95ca to your computer and use it in GitHub Desktop.
Save codehaks/492c4464ac8d2e80e2f0f51df36b95ca to your computer and use it in GitHub Desktop.
Farsi numbers
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace Portal.Infrastructure.Extentions
{
public static class StringExtentions
{
private const int ZeroCharCode = '0';
private const int LocalizedZeroCharCode = '۰';
public static string LocalizeNumbers(this string value)
{
if (string.IsNullOrEmpty(value)) return value;
var chars = value.ToCharArray();
for (var i = 0; i < chars.Length; i++)
{
var num = chars[i] - ZeroCharCode;
if (0 <= num && num < 10)
chars[i] = (char) (LocalizedZeroCharCode + num);
}
return new string(chars);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment