0
Reply

Converting iso-8859-1 to unicode

tony

tony

Jul 26 2006 11:35 AM
2.3k
Hi I'm having a bit of difficulty with some text encoding, the problem is that i have set up all posts so that "ISO-8859-1" is used so that when a user adds the pound symbol "£" in a text area field then character is encoded to "£" and if the user includes "&" in the text area then the character is encoded to "&", this is nessasay so that users can use the "£" symbol. The problem is that text area field has a character length validatoin check on it and if the user includes the "£" or "&" characters in the text then the characters are counted as 5 and 4 characters respectiveley instead of 1. I have tried to convert the string from the text area from "ISO-8859-1" to unicode so that "£" is changed to "£" using the code below but this does not seem to work. String aString = jobDescriptionTextArea.Value; Encoding latinEuropeanEncoding = System.Text.Encoding.GetEncoding("iso-8859-1"); Encoding uniCode = Encoding.Unicode; byte[] latinBytes = latinEuropeanEncoding.GetBytes(aString); byte[] unicodeBytes = Encoding.Convert(latinEuropeanEncoding, uniCode, latinBytes); char[] unicodeCharArray = new char[uniCode.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)]; uniCode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeCharArray, 0); String outputString = new String(unicodeCharArray); Response.Write("converted string >" + outputString + "<
"); Any suggestions? Cheers