发新话题
打印

中文问题的一些建议

中文问题的一些建议

  很多朋友都在开发时遇到中文问题,现在将我收集到的一些转换函数给大家公布,希望有帮助。
一般来说java都是以unicode进行编码显示,而中文常用的编码有GB2312,和UTF-8,
(不是所有输入的中文都是UNICODE,大家需要注意确认)。大家在传中文时需要自己拼结。
要把GB2312或BIG5转换成unicode 得用:
unicodeString = new String(myString.getBytes(), "GB2312");

unicodeString = new String(myString.getBytes(), "Big5");
但是在一般的手机上不同的特性可能并不支持GB2312和Big5,我所知道的moto的手机就不支持。
所以,以下函数可能用的上。(注明:并非我写的,但是都是正确的)

class transCN{
static public String convertUTF8String2Unicode(String instr)
throws IOException {
//byte[] strbytes = instr.getBytes();
int charindex = instr.length();
int actualValue;
int inputValue;
StringBuffer sbtemp = new StringBuffer();

for (int i = 0; i < charindex;) {

actualValue = -1;
inputValue = instr.charAt(i  );

inputValue

TOP

发新话题