验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

java处理字符的函数是哪个

阅读:525 来源:乙速云 作者:代码code

java处理字符的函数是哪个

1、getBytes是java字符串处理的标准函数,其作用是按照charset编码字符串所表示的字符,并以字节形式表示。

注:字符串在java内存中总是按unicode编码存储。

2、newString根据charset编码对字节数组进行组合识别,转换为unicode存储。

3、setCharacterEncoding()

该函数用于设置http请求或相应的编码。

实例

package com.test.bs;
 
import java.io.UnsupportedEncodingException;
 
public class UnicodeTest2 {
 
public static void main(String[] args) {
String a = "哈哈";
try {
byte[] gb2312 = a.getBytes("GB2312");
byte[] utf = a.getBytes("UTF-8");
for (int i = 0; i < gb2312.length; i++) {
System.out.print(gb2312[i]);
}
System.out.println();
 
for (int i = 0; i < utf.length; i++) {
System.out.print(utf[i]);
}
System.out.println();
 
System.out.println(new String(gb2312));
System.out.println(new String(utf));
System.out.println(System.getProperty("file.encoding"));//当前文件的编码方式
System.out.println(new String(utf, "UTF-8"));
System.out.println(new String(gb2312, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
 
}
}
分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>