手写转换:
功能tiontouint8arr (str ) { const buffer=[]; for(letIofstr ) const_code=I.charcodeat(0; if (代码0x 80 ) buffer.push ) _code; }elseif(_code0x800 ) buffer.push )0xc0) _code6); buffer.push(0x80 ) code0x3f ); } else if (代码0x 10000 ) buffer.push (0x E0 ) )代码12 ); buffer.push(0x80 ) code60x3f ); buffer.push(0x80 ) code0x3f ); }returnuint8array.from(buffer ); }从} Unicode迁移到utf8的规则:
优衣码符号范围|UTF-8编码方式
(十六进制)|(二进制) ) ) ) ) ) ) ) ) ) )。
------------- -请参阅
00000000-000007 f|jqdjmg/p 000000080-000007 ff|110xxxxx
玄妙的长筒袜/p 00000800-0000FFFF|1110xxxx10