Created
January 27, 2020 20:25
-
-
Save codehaks/492c4464ac8d2e80e2f0f51df36b95ca to your computer and use it in GitHub Desktop.
Farsi numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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