subject:
Special Character Conversion Problems – ISO-8859-1 to Unicode
[print this page]
public static string iso8859ToUnicode(string textToConvert) { Encoding iso8859 = Encoding.GetEncoding("iso-8859-1"); Encoding unicode = Encoding.Unicode; byte[] srcTextBytes = iso8859.GetBytes(textToConvert); byte[] destTextBytes = Encoding.Convert(iso8859,unicode, srcTextBytes); char[] destChars = new char[unicode.GetCharCount(destTextBytes, 0, destTextBytes.Length)]; unicode.GetChars(destTextBytes, 0, destTextBytes.Length, destChars, 0); StringBuilder result = new StringBuilder(textToConvert.Length + (int)(textToConvert.Length * 0.1)); foreach (char c in destChars) { int value = Convert.ToInt32(c); if (value > 127) result.AppendFormat("{0};", value); else result.Append(c); } return result.ToString(); }
Special Character Conversion Problems ISO-8859-1 to Unicode
By: Chris Bishop
welcome to loan (http://www.yloan.com/)
Powered by Discuz! 5.5.0