Dart编程语言中的字符串属性 codeunits 返回字符串的字符的 UTF-16 代码列表。直接查找 UTF-16 代码单元是非常有用的字符串属性。
Syntax: String.codeUnits
Returns: a list of UTF-16 code units
示例 1:
Dart
// main function start
void main() {
// initialize string st
String st = "Geeksforgeeks";
// print the UTF-16 code
print(st.codeUnits);
}
Dart
// main function start
void main() {
// initialize string st
String st = "Computer";
// print the UTF-16 code
print(st.codeUnits);
}
输出:
[71, 101, 101, 107, 115, 102, 111, 114, 103, 101, 101, 107, 115]
示例 2:
Dart
// main function start
void main() {
// initialize string st
String st = "Computer";
// print the UTF-16 code
print(st.codeUnits);
}
输出:
[67, 111, 109, 112, 117, 116, 101, 114]