unicode 转 中文 ~~~急~~~ "中文乱码".getBytes("GBK").toString() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 "中文乱码".getBytes("GBK").toString()不行,出来乱码 江蘇舜天股份有限公司与下面对应\u6c5f\u8607\u821c\u5929\u80a1\u4efd\u6709\u9650\u516c\u53f827743=0x6c5f34311=0x8607......C:\Documents and Settings\Admin>native2ascii -reverse\u6c5f\u8607\u821c\u5929\u80a1\u4efd\u6709\u9650\u516c\u53f8 (回车)江蘇舜天股份有限公司C:\Documents and Settings\Admin>native2ascii江蘇舜天股份有限公司 (回车)\u6c5f\u8607\u821c\u5929\u80a1\u4efd\u6709\u9650\u516c\u53f8 程序怎么转?我这些数据是从数据库提取出来的,在这个column 栏位下中文数据的就转为以上的unicode,英文的保持不变.有办法吗? // Convert.javaimport java.util.regex.*;import java.io.*;public class Convert{ public static String toGB(String original) throws IOException { StringBuffer converted = new StringBuffer(); Pattern pattern = Pattern.compile("&#\\d+;"); //正则表达式匹配&#?; Matcher matcher = pattern.matcher(original); int lastEnd = 0; //上一次匹配的结束位置 while (matcher.find()) //找一下个匹配串 { if (lastEnd != matcher.start()) //写正常英文字符 { converted.append(original.substring(lastEnd, matcher.start())); } String oneByte = matcher.group(); oneByte = oneByte.substring(2, oneByte.length() - 1); //取出&#?;中的? int data = Integer.parseInt(oneByte); converted.append((char)data); lastEnd = matcher.end(); } if (lastEnd < original.length()) //写剩下的正常英文字符 { converted.append(original.substring(lastEnd)); } return converted.toString(); } public static void main(String[] args) throws IOException { String originalA = "江蘇舜天股" + "份有限公司"; String originalB = "&#China#&江蘇Hello, 舜天股" + "份World!;有限#公;司#PRC&;#"; String convertedA = Convert.toGB(originalA); String convertedB = Convert.toGB(originalB); System.out.println(convertedA); System.out.println(convertedB); } }输出为:江蘇舜天股份有限公司&#China#&江蘇Hello, 舜天股份World!;有限#公;司#PRC&;#Press any key to continue...两组测试数据均正确。 Matcher 这么强?程式终于搞定了 谢谢 java7的API中文版的 java WEB求助 java截取一篇文章的第一个段落 sql 正则表达式 这个为什么不能运行呢? 想请教下大家,学JAVA的GUI有什么有书比较好? 一个数据库查询问题,在线等待!急!!! 很难的问题,高手才进来 为什么我连接ORACLE数据库总是报错? 两个引人问题 内存问题 在IE中java Web start启动jnlp文件,老是启动不了我的jar应用,在jrun中如何配置mime文件类型?
不行,出来乱码
与下面对应
\u6c5f\u8607\u821c\u5929\u80a1\u4efd\u6709\u9650\u516c\u53f8
27743=0x6c5f
34311=0x8607
......C:\Documents and Settings\Admin>native2ascii -reverse
\u6c5f\u8607\u821c\u5929\u80a1\u4efd\u6709\u9650\u516c\u53f8 (回车)
江蘇舜天股份有限公司C:\Documents and Settings\Admin>native2ascii
江蘇舜天股份有限公司 (回车)
\u6c5f\u8607\u821c\u5929\u80a1\u4efd\u6709\u9650\u516c\u53f8
import java.io.*;public class Convert
{
public static String toGB(String original) throws IOException
{
StringBuffer converted = new StringBuffer();
Pattern pattern = Pattern.compile("&#\\d+;"); //正则表达式匹配&#?;
Matcher matcher = pattern.matcher(original);
int lastEnd = 0; //上一次匹配的结束位置
while (matcher.find()) //找一下个匹配串
{
if (lastEnd != matcher.start()) //写正常英文字符
{
converted.append(original.substring(lastEnd, matcher.start()));
}
String oneByte = matcher.group();
oneByte = oneByte.substring(2, oneByte.length() - 1); //取出&#?;中的?
int data = Integer.parseInt(oneByte);
converted.append((char)data);
lastEnd = matcher.end();
}
if (lastEnd < original.length()) //写剩下的正常英文字符
{
converted.append(original.substring(lastEnd));
}
return converted.toString();
}
public static void main(String[] args) throws IOException
{
String originalA = "江蘇舜天股"
+ "份有限公司";
String originalB = "&#China#&江蘇Hello, 舜天股"
+ "份World!;有限#公;司#PRC&;#";
String convertedA = Convert.toGB(originalA);
String convertedB = Convert.toGB(originalB);
System.out.println(convertedA);
System.out.println(convertedB);
}
}输出为:
江蘇舜天股份有限公司
&#China#&江蘇Hello, 舜天股份World!;有限#公;司#PRC&;#
Press any key to continue...两组测试数据均正确。
程式终于搞定了 谢谢