1. Because of the project encountered in the server-side jar package program, to the foreground message, the previous paragraph received a message garbled situation, so take the message string before sending the message to ASCII code before sending to the foreground, The foreground takes a solution that turns the ASCII code into a string before receiving a background message.
1) Java method for turning strings into ASCII
Public Staticstring Stringtoascii (String value) {StringBuffer SBU=NewStringBuffer (); Char[] chars =Value.tochararray (); for(inti = 0; i < chars.length; i++) { if(I! = chars.length-1) {sbu.append (int) Chars[i]. Append (","); } Else{sbu.append (int) chars[i]); } } returnsbu.tostring (); }
2) Java method for turning ASCII into a string
Public Static string asciitostring (string value) { new stringbuffer (); = Value.split (","); for (int i = 0; i < chars.length; i++) { sbu.append ((char) Integer.parseint ( Chars[i])); } return sbu.tostring (); }
Main method Test:
Public Static void Main (string[] args) { = "{name:1234,password:4444}"; = stringtoascii (str); System.out.println (Asciiresult); = asciitostring (asciiresult); System.out.println (Stringresult); }
Output:
123,110,97,109,101,58,49,50,51,52,44,112,97,115,115,119,111,114,100,58,52,52,52,52,125{name:1234, password:4444}
Java string and ASCII transcoding