« Home | The Controls collection cannot be modified because... » | Team Foundation PowerToys » | String is All Lower or All Upper Case » | Detecting Chrome browser in ASP.NET » | Chart Control for .net 3.5 » | Increase the VS screen for HTML pages » | Working with Dynamic Controls » | Dynamics CRM 4.O SDK for IPHONE » | Sql Injection Tracking Tool » | Using LogParser to get Download Details from IIS »

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...

Labels: , , , , ,

Post a Comment