当前位置:网站首页>【原创】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));
边栏推荐
- js例题打印1-100之间所有7的倍数的个数及总和
- What is a flotation machine?
- JVM层次上的对象的创建过程和内存布局
- Pin details in rust
- Etcd教程 — 第五章 Etcd之etcdctl的使用
- JS output all prime numbers between 1-100 and calculate the total number
- 野風藥業IPO被終止:曾擬募資5.4億 實控人俞蘠曾進行P2P投資
- 【批处理DOS-CMD命令-汇总和小结】-将文件夹映射成虚拟磁盘——subst
- 【批处理DOS-CMD命令-汇总和小结】-cmd的内部命令和外部命令怎么区分,CMD命令和运行(win+r)命令的区别,
- Win10 how to manage startup items?
猜你喜欢

Win10 how to manage startup items?

js用switch输出成绩是否合格

What is a magnetic separator?

js用switch语句根据1-7输出对应英文星期几
![[13. number and bit operation of 1 in binary]](/img/53/024f9742d1936fe6f96f4676cea00e.png)
[13. number and bit operation of 1 in binary]

【批处理DOS-CMD命令-汇总和小结】-环境变量、路径变量、搜索文件位置相关指令——set、path、where,cmd命令的路径参数中有空格怎么办

100%弄明白5种IO模型

Recognize the ordering of O (nlogn)
![[batch dos-cmd command - summary and summary] - output / display command - echo](/img/44/cddad70eeb756db15c19100c25c61a.png)
[batch dos-cmd command - summary and summary] - output / display command - echo

js成绩奖惩例题
随机推荐
[c++ primer notes] Chapter 4 expression
c的时间函数算效率
【批处理DOS-CMD命令-汇总和小结】-cmd的内部命令和外部命令怎么区分,CMD命令和运行(win+r)命令的区别,
LVGL GUI GUIDER移植代码到STM32
JS, and output from small to large
[batch dos-cmd command - summary and summary] - map folder to virtual disk - subst
If xn > 0 and X (n+1) /xn > 1-1/n (n=1,2,...), Prove that the series Σ xn diverges
大厂工作十年,年薪40万突然被裁员,公司想抛弃你,一分情面都不会留
js成绩奖惩例题
MySQL environment variable configuration tutorial
"Short video" Linxia fire rescue detachment carries out fire safety training
js中输入三个值,并且由小到大输出
索引+sql练习优化
Win10 how to manage startup items?
一种太阳能电荷泵供电电路的方案设计
Mysql-8 download, installation and configuration tutorial under Windows
Pin details in rust
二叉树结构以及堆结构基础
JS output shape
How can I import data from Oracle into fastdfs?