`

unicode下的String

阅读更多
先看一个代码
String o="1";
System.out.println(o.getBytes("unicode").length);
System.out.println(o.getBytes("iso-8859-1").length);
System.out.println(o.getBytes("gbk").length);

输出
4
1
1
首先unicode对字符是采用双字节存储 也就是这里 一个是 两个字节 !可能在开头或者结尾有种结尾符!!

为了在读取字节时能知道所采用的字节序,在传输时采用了一个名为
“ZERO WIDTH NON-BREAKING SPACE”(U+FEFF)的字符用于限定字节
序,开头两个字节为 FE FF 时为 Big-Endian,为 FF FE 时为 Little-Endian。
详见 RFC2781 3.2 节。

在 Java 中直接使用 Unicode 转码时会按照 UTF-16LE 的方式拆分,并加上 BOM。

如果采用 UTF-16 拆分,在 Java 中默认采用带有 BOM 的 UTF-16BE 拆分。

看这个连接 理解 rfc
http://www.docin.com/p-6587198.html
分享到:
评论

相关推荐

    一个驱动开发中UNICODE_STRING的封装类CUString

    在Windows系统中,内核模式驱动程序经常需要处理UNICODE_STRING结构体,它用于表示Unicode字符串。本篇文章将详细探讨CUString,这是一个针对UNICODE_STRING进行封装的类,旨在简化驱动开发中的字符串操作,类似于...

    unicode_string_src.zip_CUnicodeString pudn_UnicodeString.cpp_uni

    5. **UnicodeString.h**:这是CUnicodeString类的头文件,通常包含了类的声明,包括类的定义、常量、枚举、函数原型等。开发人员在其他源文件中需要使用CUnicodeString类时,需要包含此头文件来获取类的接口信息。 ...

    C++Builder String,UNICODE,UTF8,ANSI互转的类.rar_c

    在C++Builder中,`String`类型是基于Unicode的,这意味着默认情况下,它存储的是宽字符(每个字符2字节),这与Windows API中的`WCHAR`和`LPCWSTR`类型相匹配。这种设计使得C++Builder可以方便地处理包含多语言字符...

    replace-unicode-string.rar_ Unicode Reader _Work It

    replace-unicode-string: a small tool used to replace unicodes strings in unicode file ( when we use sed -i on windows, it would not work for string replacement on unicode file, so I wrote these tool)....

    String转换Unicode编码转换

    就是从String转换成Unicode和从Unicode转换成String编码转换

    xe5 android Escape UnicodeString to String

    "xe5 android Escape UnicodeString to String" 这个主题涉及到的是如何将包含Unicode转义序列的字符串转换为可读的UTF-8编码的字符串。Unicode是一种广泛使用的字符集,它包含了世界上大部分语言的字符。然而,当...

    a very useful link to covert the non-unicode string to the unicode one

    a very useful link to covert the non-unicode string to the unicode one a very useful link to covert the non-unicode string to the unicode one a very useful link to covert the non-unicode string to the...

    Unicode CString和 std::string 的完美转换,不会有64K限制

    本话题主要关注Unicode中的CString(通常是MFC或ATL中的CAtlString或者CStringT)与C++标准库中的std::string之间的高效且无64K限制的转换。 Unicode是一种广泛采用的字符编码标准,能够表示世界上几乎所有的字符。...

    字符串转Unicode小工具程序

    总之,“字符串转Unicode小工具程序”是VB6.0环境下处理字符编码问题的一个实用工具,它能够帮助开发者和用户在LCD、触摸屏等设备上正确处理各种语言的文本。理解Unicode编码的原理以及如何在VB6.0中进行转换,对于...

    Unicode 转换为字符串小工具

    Unicode是一种国际字符编码标准,旨在容纳世界上几乎所有的文字和符号,包括中文、英文、日文、希腊文等。它的全称是Universal Multiple-Octet Coded Character Set,简称UCS。Unicode编码采用二进制形式,可以表示...

    C# GB2312转成Unicode

    本文将深入探讨如何在C#编程环境下将GB2312编码转换为Unicode编码,以解决Unity Web Player对GB2312编码不支持的问题。 首先,让我们了解下GB2312编码。GB2312,全称“汉字国标交换码”,是中国大陆的国家标准汉字...

    Java String字符串和Unicode字符相互转换代码详解

    public static String unicode2String(String unicode) { StringBuffer string = new StringBuffer(); String[] hex = unicode.split("\\\\u"); for (int i = 1; i ; i++) { int data = Integer.parseInt(hex[i]...

    VB6读写Unicode_vb6_unicode_

    Dim unicodeStr As String unicodeStr = "你好,世界!" Print #fileNum, unicodeStr Close #fileNum ``` 注意,如果你的字符串是ANSI的,需要先转换为Unicode,可以使用`StrConv`函数完成: ```vb unicodeStr = ...

    C# 格式的ASCII到Unicode转化源码

    Console.WriteLine("Unicode String: {0}", unicodeString); } } ``` 在这个例子中,我们首先获取了一个ASCII字符串,并将其转换为字节数组。然后,我们创建了一个`UnicodeEncoding`对象,并使用`Buffer.Block...

    易语言c++结构Unicode传递处理

    本主题聚焦于易语言与C++之间的交互,特别是涉及到Unicode字符串的处理。Unicode是一种国际标准,用于表示世界上几乎所有的字符集,确保了跨语言的文本处理能力。 在易语言中,字符串通常是基于GBK编码的,而在C++...

    android GBK转换为String

    String unicodeStr = new String(gbkBytes, "GBK"); ``` 2. **Unicode转GBK(字符串)**: - 反之,如果已有Unicode字符串,需要编码成GBK,可以使用`CharsetEncoder`: ```java String unicodeStr = ...; // ...

    C++类型转换(char* string cstring unicode ansi )转换

    CString 和 Unicode 之间的转换是非常常见的操作,特别是在 Unicode 环境下。 CString 转 Unicode: CString cstr; double d = _wtof(cstr.GetString()); 这段代码将 CString 对象 cstr 转换成 Unicode 编码的 ...

    Java String字符串和Unicode字符相互转换代码

    public static String string2Unicode(String string) { StringBuffer unicode = new StringBuffer(); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); unicode.append("\\u" + ...

    中文转化为unicode格式的方法类

    在编程领域,Unicode 是...`unicodeConvert.java` 类是实现这一功能的代码载体,它可以方便地在各种场景下进行中文字符与 Unicode 之间的转换。理解和掌握这些概念与方法对于进行多语言编程和处理国际化问题至关重要。

    CString string char 之间的相互转换

    CString string_to_CString_unicode(std::string str) CString string_to_CString_unicode_Ex(std::string& str) CString string_to_CString_ansi(std::string str) CString string_to_CString_ansi_Ex(std::string&...

Global site tag (gtag.js) - Google Analytics