当前位置:网站首页>【原创】TypeScript字符串utf-8编码解码
【原创】TypeScript字符串utf-8编码解码
2022-06-27 08:06:00 【赵庆明老师】
定义一个字符串(原始数据)
将其使用utf8编码成一个数组(编码)
再将其解码成一个字符串(还原)
let str1 = "我们①this is a string";
//我们①this is a string
console.log(str1);
const byteArray = new TextEncoder().encode(str1);
//Uint8Array(25) [
// 230, 136, 145, 228, 187, 172,
// 226, 145, 160, 116, 104, 105,
// 115, 32, 105, 115, 32, 97,
// 32, 115, 116, 114, 105, 110,
// 103
//]
console.log(byteArray);
//19
console.log(str1.length);
//25
console.log(byteArray.length);
//我们①this is a string
console.log(new TextDecoder().decode(byteArray));
边栏推荐
猜你喜欢

Redis五种基本类型

认识O(NlogN)的排序

游戏六边形地图的实现

ZABBIX deployment instructions (server+win client + switch (H3C))

2022 love analysis · panoramic report of it operation and maintenance manufacturers

"Short video" Linxia fire rescue detachment carries out fire safety training

野風藥業IPO被終止:曾擬募資5.4億 實控人俞蘠曾進行P2P投資

一种太阳能电荷泵供电电路的方案设计

【批处理DOS-CMD命令-汇总和小结】-输出/显示命令——echo

win命令行中导入、导出数据库相关表
随机推荐
[notes on c++ primer] Chapter 3 string, vector and array
js判断用户输入的数是否为质数(多种方法)
【批处理DOS-CMD命令-汇总和小结】-将文件夹映射成虚拟磁盘——subst
(原创)自定义Drawable
索引+sql练习优化
How can I import data from Oracle into fastdfs?
2. QT components used in the project
js求所有水仙花数
MySQL环境变量配置的教程
Game asset reuse: a new way to find required game assets faster
安装jenkins
SPARQL基础入门练习
C how to call line and rows when updating the database
MySQL about auto increment sum cannot be empty
JS use the switch statement to output the corresponding English day of the week according to 1-7
[paper reading] internally semi supervised methods
JS find the number of all daffodils
Mysql事务中MVCC理解超简单
游戏六边形地图的实现
[batch dos-cmd command - summary and summary] - environment variables, path variables, search file location related instructions - set, path, where, what if there are spaces in the path parameters of