当前位置:网站首页>C#字节数组(byte[])和字符串相互转换
C#字节数组(byte[])和字符串相互转换
2022-04-23 17:54:00 【IT技术猿猴】
通过C#中的system.text.encoding获取字符串的编码可以有ASCII,DEFAULT,utf-8以及其他一些方式,对于英文而言这几种所获取的编码是没有太大区别的,而中文则大有不同,其中DEFAULT所采取的是GB2312,可以通过一下方式进行确认,程序运行后会发现bufOfGB和buf是相同的
string str = "hello,我的祖国";
byte[] bufOfGB = System.Text.Encoding.GetEncoding("gb2312").GetBytes(str);
Array.ForEach(bufOfGB,m=>Console.WriteLine(m));
Console.WriteLine(System.Text.Encoding.Default);
byte[] buf = System.Text.Encoding.Default.GetBytes(str);
Array.ForEach(buf,m=>Console.WriteLine(m));
Console.WriteLine("-------------");
byte[] bufOfASCII = System.Text.Encoding.ASCII.GetBytes(str);
Array.ForEach(bufOfASCII,m=>Console.WriteLine(m));
Console.WriteLine("-------------");
byte[] bufOfUTF = System.Text.Encoding.UTF8.GetBytes(str);
Array.ForEach(bufOfUTF,m=>Console.WriteLine(m));
Console.WriteLine("-------------");
byte[] byteArray ={43,45,67,88,23,1f}
string str = System.Text.Encoding.Default.GetString(byteArray);
版权声明
本文为[IT技术猿猴]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baobingji/article/details/124364638
边栏推荐
- Flask项目的部署详解
- Index: teach you index from zero basis to proficient use
- 2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
- 2022年流动式起重机司机国家题库模拟考试平台操作
- Hcip fifth experiment
- MySQL advanced index [classification, performance analysis, use, design principles]
- QT modification UI does not take effect
- Halo open source project learning (II): entity classes and data tables
- 圆环回原点问题-字节跳动高频题
- ros常用的函数——ros::ok(),ros::Rate,ros::spin()和ros::spinOnce()
猜你喜欢

01 - get to know the advantages of sketch sketch

Kubernetes 服务发现 监控Endpoints

土地覆盖/利用数据产品下载

Kubernetes service discovery monitoring endpoints

102. 二叉树的层序遍历

SystemVerilog(六)-变量

The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time

Matlab / Simulink simulation of double closed loop DC speed regulation system

Future usage details

Halo 开源项目学习(二):实体类与数据表
随机推荐
Submit local warehouse and synchronize code cloud warehouse
2022年流动式起重机司机国家题库模拟考试平台操作
Add animation to the picture under V-for timing
01 - get to know the advantages of sketch sketch
Thirteen documents in software engineering
Halo 开源项目学习(二):实体类与数据表
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
On the problem of V-IF display and hiding
Flask项目的部署详解
ES6 face test questions (reference documents)
Kubernetes 服务发现 监控Endpoints
48. Rotate image
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
Leak detection and vacancy filling (VII)
JVM class loading mechanism
开源按键组件Multi_Button的使用,含测试工程
239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
EasymodbusTCP之clientexample解析