当前位置:网站首页>C byte array (byte []) and string are converted to each other
C byte array (byte []) and string are converted to each other
2022-04-23 17:56:00 【It technology ape】
adopt C# Medium system.text.encoding The encoding of the obtained string can be ASCII,DEFAULT,utf-8 And other ways , For English, there is no big difference between these codes , Chinese is very different , among DEFAULT What has been taken is GB2312, It can be confirmed in the following ways , After the program runs, you will find bufOfGB and buf It's the same
string str = "hello, My motherland ";
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 technology ape]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231753552278.html
边栏推荐
- 油猴网站地址
- Sword finger offer 03 Duplicate number in array
- MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
- 云原生虚拟化:基于 Kubevirt 构建边缘计算实例
- Logic regression principle and code implementation
- 402. Remove K digits - greedy
- Type judgment in [untitled] JS
- Cloud native Virtualization: building edge computing instances based on kubevirt
- 48. Rotate image
- Go's gin framework learning
猜你喜欢
随机推荐
102. 二叉树的层序遍历
Halo open source project learning (II): entity classes and data tables
Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
JS forms the items with the same name in the array object into the same array according to the name
Applet learning notes (I)
Land cover / use data product download
31. Next arrangement
Thirteen documents in software engineering
2022年上海市安全员C证操作证考试题库及模拟考试
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
JS implementation private attribute
Leak detection and vacancy filling (VII)
Chrome浏览器的跨域设置----包含新老版本两种设置
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
Transfer learning of five categories of pictures based on VGg
SystemVerilog (VI) - variable
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
Uniapp custom search box adaptation applet alignment capsule
MySQL advanced index [classification, performance analysis, use, design principles]









