将中文转为unicode 及转回中文函数
来源:互联网 发布:图标是猫编程软件下载 编辑:程序博客网 时间:2024/05/06 01:52
//转为unicode
public static void writeUnicode(final DataOutputStream out, final String value) {
try {
final String unicode = gbEncoding( value );
final byte[] data = unicode.getBytes();
final int dataLength = data.length;
System.out.println( "Data Length is: " + dataLength );
System.out.println( "Data is: " + value );
out.writeInt( dataLength ); //先写出字符串的长度
out.write( data, 0, dataLength ); //然后写出转化后的字符串
} catch (IOException e) {
}
}
public static String gbEncoding( final String gbString ) {
char[] utfBytes = gbString.toCharArray();
String unicodeBytes = "";
for( int byteIndex = 0; byteIndex < utfBytes.length; byteIndex ++ ) {
String hexB = Integer.toHexString( utfBytes[ byteIndex ] );
if( hexB.length() <= 2 ) {
hexB = "00" + hexB;
}
unicodeBytes = unicodeBytes + "////u" + hexB;
}
System.out.println( "unicodeBytes is: " + unicodeBytes );
return unicodeBytes;
}
/*****************************************************
* 功能介绍:将unicode字符串转为汉字
* 输入参数:源unicode字符串
* 输出参数:转换后的字符串
*****************************************************/
private String decodeUnicode( final String dataStr ) {
int start = 0;
int end = 0;
final StringBuffer buffer = new StringBuffer();
while( start > -1 ) {
end = dataStr.indexOf( "////u", start + 2 );
String charStr = "";
if( end == -1 ) {
charStr = dataStr.substring( start + 2, dataStr.length() );
} else {
charStr = dataStr.substring( start + 2, end);
}
char letter = (char) Integer.parseInt( charStr, 16 ); // 16进制parse整形字符串。
buffer.append( new Character( letter ).toString() );
start = end;
}
return buffer.toString();
}
- 将中文转为unicode 及转回中文函数
- 将中文转为unicode 及转回中文函数
- 将中文转为unicode 及转回中文函数
- PHP 中文 转UNICODE, JS 将UNICODE转为GBK
- 中文转为unicode编码
- 中文转为unicode编码
- sql中函数将金额转为中文
- 将中文数字转为阿拉伯数字
- 将中文转为拼音 iOS
- 中文转为unicode的字符串形式
- Java实现Unicode码转为中文
- 中将中文转为拼音首字母的函数及调用方法
- 将中文转换成unicode
- 将UNICODE 转换为中文
- Java将Unicode转中文
- 将unicode编码转成中文
- 将日期转为中文字符的类
- 将阿拉伯数字转为中文大写读法
- FUTo
- 使用 Visual C# .Net 确定 Windows 版本
- 详细说明java集合框架的体系结构
- [network]
- 过滤不安全代码!
- 将中文转为unicode 及转回中文函数
- 关于前面提到的 vc bug 有误
- Repeater控件技巧,放在这里省得用时找不到。
- 谈文化现象思考(主管总是谈文化)
- 二十多年的程序开发之路: 感受篇-----(袁峰)
- JBuilder
- 接入路由器做NAT,做限速的一些想法
- sql server2000的BCP的使用技巧
- VC编程改变指定的文件或文件夹的属性