1. As a result of the project encountered in the server-side jar package program, send a message to the front desk, the previous paragraph received the message garbled situation, so take the message before sending the message string into an ASCII code before sending to the front desk, The foreground takes a solution that turns the ASCII code into a string before receiving the background message.
1 Java method for converting strings to ASCII
public static string Stringtoascii (string value) {StringBuffer SBU = new StringBuffer (); char[] chars = Value.tochararray (); for (int i = 0; i < chars.length i++) {if (I!= chars.length-1) {sbu.append ((int) chars[i]). Append (",");} else {SB U.append ((int) chars[i]); } return sbu.tostring (); }
2 Java method for converting ASCII to strings
public static string Asciitostring (string value) {StringBuffer SBU = new StringBuffer (); string[] chars = Value.split (","); for (int i = 0; i < chars.length i++) {sbu.append ((char) integer.parseint (chars[i)), return sbu.tostring (); }
Test methods and Results
public static void Main (string[] args) {
String str = "Peng Yujun";
String Asciiresult = stringtoascii (str);
System.out.println (Asciiresult);
String Stringresult = asciitostring (Asciiresult);
System.out.println (Stringresult);
}
Console output 24429,29577,20891 Peng Yujun