how to convert Unicode to ASCII text
- This topic has 2 replies, 2 voices, and was last updated 9 years, 1 month ago by Randy Paries.
-
AuthorPosts
-
September 2, 2015 at 4:46 pm #9053Randy PariesParticipant
hello,
I have a couple SF400-G’s and i am using the API to send the text messages to my servers.
When a user sends a message from their IPHONe and uses an emoji i get the message in the form of<?xml version="1.0" encoding="ISO-8859-1"?> <Response> <Msg_Count>1</Msg_Count> <MessageNotification> <Message_Index>1</Message_Index> <ModemNumber>1:256xxxxxx</ModemNumber> <SenderNumber>+1231xxxxxx</SenderNumber> <Date>15/09/01</Date> <Time>15:15:20</Time> <EncodingFlag>Unicode</EncodingFlag> <Message>05000339020100480065006C006C006F002000520061006E006400790020007400680069007300200069007300200061002000740065007300740020006D007300730067002000770069007400680020006D007900200061007700650073006F006D006500200049002000700068006F006E00650020006C006F006C0020D83DDE01D83DDE30D83D</Message> </MessageNotification> </Response>
I have tried numerous ways to convert this to ascii. tried a number of online sites where you can paste in your unicode and it will try.
Has anyone converted this to ascii text? I am using JAVA on the server so i have many options, just can not seem to figure out what actual format the message is in
thanks for any help
r
September 9, 2015 at 10:26 am #9124Bryon DavisModeratorHi Randy,
The Unicode message the iSMS delivers have the Unicode characters in groups of 4 hex digits. So the first character in the message you posted is “0500” (CYRILLIC CAPITAL LETTER KOMI DE) and the second character is “0339”. I’m not sure why the iPhone is sending these odd characters, they must mean something to another iPhone.You can convert the Unicode characters into something readable with a programming language like JAVA. Below is an example of code to convert the iSMS Unicode hex string into a readable JAVA string. Note that with the iPhone sending odd Unicode characters, there will be some characters that look like gibberish.
public class convert_unicode { public static void main(String[] args) { String unicodeString = new String(""); String fourhex = new String (""); String unicodeHexString = new String("05000339020100480065006C006C006F002000520061006E006400790020007400680069007300200069007300200061002000740065007300740020006D007300730067002000770069007400680020006D007900200061007700650073006F006D006500200049002000700068006F006E00650020006C006F006C0020D83DDE01D83DDE30D83D"); System.out.println("Unicode Hex String from iSMS: " + unicodeHexString); // Convert Unicode hex string from iSMS to a Java string with Unicode characters. int charPtr = 0; while (true) { if ((unicodeHexString.length()-charPtr)<4) { break; } fourhex = unicodeHexString.substring(charPtr, charPtr+4); charPtr += 4; char c = (char) Integer.parseInt(fourhex, 16); unicodeString += c; } System.out.println("Parsed Unicode String:" + unicodeString); // Convert Unicode values in string to UTF-8 byte[] utf8Bytes = null; String convertedString = null; try { System.out.println(unicodeString); utf8Bytes = unicodeString.getBytes("UTF8"); convertedString = new String(utf8Bytes, "UTF8"); System.out.println("Converted UTF-8 String:" + convertedString); //same as the original string } catch (Exception e) { e.printStackTrace(); } } }
Hope this helps.
Bryon
September 10, 2015 at 10:04 pm #9168Randy PariesParticipantThis is Perfect. I really appreciate this. it works just like i need
-
AuthorPosts
- You must be logged in to reply to this topic.