字符串与ASCII的转换
Posted 工程哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串与ASCII的转换相关的知识,希望对你有一定的参考价值。
public class ASCIIUtil
public static void main(String[] args)
System.out.println(stringToAscii("hello嗨喽"));
System.out.println(asciiToString("104,101,108,108,111,21992,21949"));
public static String stringToAscii(String value)
StringBuffer stringBuffer = new StringBuffer();
char[] chars = value.toCharArray();
for (char c : chars)
stringBuffer.append((int) c).append(",");
return stringBuffer.toString().substring(0, stringBuffer.length() - 1);
public static String asciiToString(String value)
StringBuffer stringBuffer = new StringBuffer();
String[] chars = value.split(",");
for(String c : chars)
stringBuffer.append((char) Integer.parseInt(c));
return stringBuffer.toString();
以上是关于字符串与ASCII的转换的主要内容,如果未能解决你的问题,请参考以下文章