我尝试在如何在 Dart 中使用 char 类型中实现 Irn 答案?(打印字母)但没有确切地知道如何去做。
示例在我的 Dart 代码中,上面带有点的大写i 表示为字节 [304],我必须将其替换为服务器字节 [152],并将其作为字节而不是字符串发送到服务器。
测试一:
cpToLatin9(int cp) => const {0x11e: 0xd0, 0x11f: 0xf0, 0x130: 0xdd, 0x131: 0xfd, 0x15e: 0xde, 0x15f: 0xfe}[cp] ?? cp;
latin9ToCp(int latin9Char) => const {0xd0: 0x11e, 0xf0: 0x11f, 0xdd: 0x130, 0xfd: 0x131, 0xde: 0x15e, 0xfe: 0x15f}[latin9Char] ?? latin9Char;
String iso08859_9 = "çÇğĞıİşŞöÖüÜ";
List<int> bytes = utf8.encode(iso08859_9);
for (var i = 0; i < bytes.length; i++) {
int byte = bytes[i];
var latin9ToCodePoint = latin9ToCp(byte);
print("latin9ToCodePoint: $latin9ToCodePoint");
var latin9ToCodePointChar = String.fromCharCode(latin9ToCodePoint);
print("latin9ToCodePointChar: $latin9ToCodePointChar");
}
输出:
iso08859_9 bytes: [195, 167, 195, 135, 196, 159, 196, 158, 196, 177, 196, 176, 197, 159, 197, 158, 195, 182, 195, 150, 195, 188, 195, 156]
latin9ToCodePoint: 195
latin9ToCodePointChar: Ã
latin9ToCodePoint: 167
latin9ToCodePointChar: §
latin9ToCodePoint: 195
latin9ToCodePointChar: Ã
latin9ToCodePoint: 135
latin9ToCodePointChar:
latin9ToCodePoint: 196
latin9ToCodePointChar: Ä
latin9ToCodePoint: 159
latin9ToCodePointChar:
latin9ToCodePoint: 196
latin9ToCodePointChar: Ä
latin9ToCodePoint: 158
latin9ToCodePointChar:
latin9ToCodePoint: 196
latin9ToCodePointChar: Ä
latin9ToCodePoint: 177
latin9ToCodePointChar: ±
latin9ToCodePoint: 196
latin9ToCodePointChar: Ä
latin9ToCodePoint: 176
latin9ToCodePointChar: °
latin9ToCodePoint: 197
latin9ToCodePointChar: Å
latin9ToCodePoint: 159
latin9ToCodePointChar:
latin9ToCodePoint: 197
latin9ToCodePointChar: Å
latin9ToCodePoint: 158
latin9ToCodePointChar:
latin9ToCodePoint: 195
latin9ToCodePointChar: Ã
latin9ToCodePoint: 182
latin9ToCodePointChar: ¶
latin9ToCodePoint: 195
latin9ToCodePointChar: Ã
latin9ToCodePoint: 150
latin9ToCodePointChar:
latin9ToCodePoint: 195
latin9ToCodePointChar: Ã
latin9ToCodePoint: 188
latin9ToCodePointChar: ¼
latin9ToCodePoint: 195
latin9ToCodePointChar: Ã
latin9ToCodePoint: 156
latin9ToCodePointChar:
测试 2: 如果我更改List bytes = utf8.encode(iso08859_9); 至
列表字节 = iso08859_9.codeUnits; 我得到不同的结果。
在我的 Dart 中,我测试了 iso08859_9 字符是否表示为 iso08859_9 字节:
[231、199、287、286、305、304、351、350、246、214、252、220]
现在我的主要问题是将字节更改为IBM CP 字节
[135、128、167、166、141、152、159、158、148、153、129、154]
当我这样做并使用 socket.add(ibmcp_bytes) 来服务器时,该字符也不可读。
更新:
试试这个,结果找出 1 和 2 个字节。???
print("ç".runes.length);
print(utf8.encode("ç").length);