Monday, November 23, 2009

How to convert unicode character to ascii

Some old database still store data in ascii characters. However, today's website is all unicode or utf enabled. That means it's able to support more characters (such as Japanese, French, Chinese and etc).

using System.Text;

private string ConvertUnicodeToAnsi(string input)
{
if (input.Length == 0) return string.Empty;
var ascii = new ASCIIEncoding();
return ascii.GetString(ascii.GetBytes(input));
}

No comments: