Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UCS2 to text

Status
Not open for further replies.

fdservices

IS-IT--Management
Mar 10, 2005
52
FR
I am reading an sms message from a file and it is identified as "Alphabet: UCS2" instead of a more normal "Alphabet: ISO". The ISO messages read in as text while the UCS2 read in as two byte text, so I get ?T?h?i?s? ?i?s? ?t?e?x?t returned. If I use iconv to convert the text I get an "incomplete character or shift sequence" error, even though the text is 16 bytes long. So the question is how do I convert UCS2 to "standard" text?

Thanks

Andrew
 
OK, I've sorted the first problem, I had added a carriage return to the end of the text, but now iconv returns a null string from the conversion. The hex of the text is 0041 0074 0020 0031 0036 002e 0035 0037 which should convert to "At 16:57".

Andrew
 
Find out with this script what encodings are available in your installation
Code:
[COLOR=#804040][b]set[/b][/color] encodings [[COLOR=#804040][b]encoding[/b][/color] names]
[COLOR=#804040][b]foreach[/b][/color] enc [COLOR=#008080]$encodings[/color] {
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"$enc"[/color]
}
and then use encoding convertfrom or encoding convertto
see doc
 
Yes that was my first thought, but for some reason it does not seem to do the job. I think it is because I have read the bytes from a file which is a compound of Ansi and UCS2, and as a result it has already converted the bytes to text. I cannot find a simple way of piping the UCS2 text to iconv either, so in the end I have simply written the code to convert the string from scratch.

Thanks for the helps anyway.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top