Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么选择StringObject';s方法chars()返回字符串';s char[]作为u2*_Android_Dalvik - Fatal编程技术网

Android 为什么选择StringObject';s方法chars()返回字符串';s char[]作为u2*

Android 为什么选择StringObject';s方法chars()返回字符串';s char[]作为u2*,android,dalvik,Android,Dalvik,Blow是dalvik/vm/oo/Object.h中StringObject结构的定义 struct StringObject : Object { /* variable #of u4 slots; u8 uses 2 slots */ u4 instanceData[1]; /** Returns this string's length in characters. */ int length() const; /** * Returns this str

Blow是dalvik/vm/oo/Object.h中StringObject结构的定义

struct StringObject : Object {
/* variable #of u4 slots; u8 uses 2 slots */
u4              instanceData[1];

/** Returns this string's length in characters. */
int length() const;

/**
 * Returns this string's length in bytes when encoded as modified UTF-8.
 * Does not include a terminating NUL byte.
 */
int utfLength() const;

/** Returns this string's char[] as an ArrayObject. */
ArrayObject* array() const;

/** Returns this string's char[] as a u2*. */
const u2* chars() const;
};
如何使用StringObject打印实际字符串?我已尝试,但无法从方法chars()获取字符串

还有,为什么StringObject的方法chars()返回字符串的char[]作为u2*


有什么建议吗?提前感谢。

这是一个utf-16编码字符串,因此每个代码单元为16位。因此,u2*

如何将其打印到系统日志中?我使用ALOG(LOG_WARN,“%s”…),但只获取字符串的第一个字符。UTF-16和UTF-32编码使用nul字节对小代码进行编码,因此它们不能用C中的printf打印。那么为什么Dalvik用UTF-16对字符串进行编码呢?非常感谢!我已经找到了答案。Dalvik使用utf-16编码字符串,因为JAVA使用utf-16编码字符串。在文件dalvik/vm/UtfString.cpp中有一个名为convertutf16tout08(…)的方法,它将utf16字符串(u2*)转换为utf8字符*。dalvik在utf-16中对字符串进行编码,因为JAVA使用utf-16对字符串进行编码。在文件dalvik/vm/UtfString.cpp中有一个名为convertutf16tout08(…)的方法,将utf16字符串(u2*)转换为utf8字符*。