当前位置:网站首页>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
边栏推荐
- Remember using Ali Font Icon Library for the first time
- 2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
- 01 - get to know the advantages of sketch sketch
- Amount input box, used for recharge and withdrawal
- 198. 打家劫舍-动态规划
- Kubernetes service discovery monitoring endpoints
- Leak detection and vacancy filling (VII)
- Comparison between xtask and kotlin coroutine
- 41. The first missing positive number
- 【Appium】通过设计关键字驱动文件来编写脚本
猜你喜欢
2022 tea artist (primary) examination simulated 100 questions and simulated examination
Summary of common SQL statements
Tdan over half
Go语言JSON包使用
Summary of floating point double precision, single precision and half precision knowledge
Double pointer advanced -- leetcode title -- container with the most water
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
92. Reverse linked list II byte skipping high frequency question
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
极致体验,揭晓抖音背后的音视频技术
随机推荐
Halo open source project learning (II): entity classes and data tables
Add drag and drop function to El dialog
958. Complete binary tree test
Go的Gin框架学习
Eigen learning summary
Future usage details
MySQL_01_简单数据检索
31. 下一个排列
.104History
QT modification UI does not take effect
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
Halo 开源项目学习(二):实体类与数据表
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
Uniapp custom search box adaptation applet alignment capsule
Summary of common SQL statements
C1 notes [task training part 2]
MySQL进阶之索引【分类,性能分析,使用,设计原则】
394. 字符串解码-辅助栈
Go's gin framework learning