Display Numerals in Arabic Format
When you are working in multilingual website, especially in arabic language, the following code may be useful to show numbers in arabic format. Because keep in mind, there is no automatic digit localization in ASP.NET. This code will help if you are in situation where you dont want change the regional settings of the PC.
public string ConvertToArabicNumerals(string input)
{
System.Text.UTF8Encoding utf8Encoder = new UTF8Encoding();
System.Text.Decoder utf8Decoder = utf8Encoder.GetDecoder();
System.Text.StringBuilder convertedChars = new System.Text.StringBuilder();
char[] convertedChar = new char[1];
byte[] bytes = new byte[]{217,160};
char[] inputCharArray = input.ToCharArray();
foreach (char c in inputCharArray)
{
if(char.IsDigit(c))
{
bytes[1] = Convert.ToByte(160 + char.GetNumericValue(c));
utf8Decoder.GetChars(bytes, 0, 2, convertedChar, 0);
convertedChars.Append(convertedChar[0]);
}
else
{
convertedChars.Append(c);
}
}
return convertedChars.ToString();
}
Happy Coding...
public string ConvertToArabicNumerals(string input)
{
System.Text.UTF8Encoding utf8Encoder = new UTF8Encoding();
System.Text.Decoder utf8Decoder = utf8Encoder.GetDecoder();
System.Text.StringBuilder convertedChars = new System.Text.StringBuilder();
char[] convertedChar = new char[1];
byte[] bytes = new byte[]{217,160};
char[] inputCharArray = input.ToCharArray();
foreach (char c in inputCharArray)
{
if(char.IsDigit(c))
{
bytes[1] = Convert.ToByte(160 + char.GetNumericValue(c));
utf8Decoder.GetChars(bytes, 0, 2, convertedChar, 0);
convertedChars.Append(convertedChar[0]);
}
else
{
convertedChars.Append(c);
}
}
return convertedChars.ToString();
}
Happy Coding...
Labels: .net2.0, .net3.5, arabic, language, localization, microsoft
Post a Comment