国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

返回中文unicode的byte字符串

2019-11-18 13:54:59
字體:
來源:轉載
供稿:網友

  返回中文unicode的byte字符串

工作中需要這樣的功能,下面是實現代碼,比如輸入“朋友”,輸出/u0b67/UCb53

public class UnicodeByteUtil {
public static void main(String[] args) {
UnicodeByteUtil instance = new UnicodeByteUtil();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line;
try {
while ((line = reader.readLine()) != null) {
if (line.trim().equals("q")) System.exit(0);
String s = instance.getBytes(line);
System.out.//System.out.println("line:"+);
}
} catch (IOException e) {
e.printStackTrace();
}
}

String getBytes(String s) {
try {
StringBuffer out = new StringBuffer("");
byte[] bytes = s.getBytes("unicode");
for (int i = 2; i < bytes.length; i++) {
out.append("http://u");
String str = Integer.toHexString(bytes[i+1] & 0xff);
for (int j = str.length(); j < 2; j++) {
out.append("0");
}
out.append(str1);
}
return out.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
}



作者Blog:http://blog.csdn.net/superlmj/
相關文章
返回中文unicode的byte字符串
根據BOM獲得實際encoding返回相應Reader
系統尋找
xml解析器的順序
字節碼工程庫簡介
[轉載]利用 JAXB 通過 XML 模式生成 XML 文檔

對該文的評論
zhwxsytia ( 2005-01-27)
我試了一下?o應該把String getbyes(string s) 方法改為如下才可以?o否則錯誤
try {
StringBuffer out = new StringBuffer("");
byte[] bytes = s.getBytes("unicode");
for (int i = 2; i < bytes.length-1; i+=2) {
out.append("http://u");
String str = Integer.toHexString(bytes[i+1] & 0xff);
for (int j = str.length(); j < 2; j++) {
out.append("0");
}
String str1 = Integer.toHexString(bytes[i] & 0xff);

out.append(str);
out.append(str1);
}
return out.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临武县| 江华| 新乐市| 长阳| 宜兴市| 达尔| 剑阁县| 东平县| 六盘水市| 怀来县| 团风县| 丹东市| 福建省| 扎鲁特旗| 克山县| 海伦市| 扬州市| 左贡县| 六盘水市| 宁德市| 巴楚县| 卫辉市| 库尔勒市| 天峻县| 威宁| 巴马| 博客| 高邮市| 宜君县| 含山县| 陈巴尔虎旗| 山西省| 正镶白旗| 石城县| 鸡东县| 鄯善县| 桓仁| 临猗县| 文成县| 咸阳市| 大洼县|