当前位置:网站首页>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
边栏推荐
- MySQL_01_简单数据检索
- Flask项目的部署详解
- Operation of 2022 mobile crane driver national question bank simulation examination platform
- YOLOv4剪枝【附代码】
- Future usage details
- Cross domain settings of Chrome browser -- including new and old versions
- 587. Install fence / Sword finger offer II 014 Anagrams in strings
- 402. Remove K digits - greedy
- 2022制冷与空调设备运行操作判断题及答案
- 【Appium】通过设计关键字驱动文件来编写脚本
猜你喜欢
Dry goods | how to extract thumbnails quickly?
470. Rand10() is implemented with rand7()
Hcip fifth experiment
Kubernetes 服务发现 监控Endpoints
Go对文件操作
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
MySQL_01_简单数据检索
Halo open source project learning (II): entity classes and data tables
Chrome浏览器的跨域设置----包含新老版本两种设置
随机推荐
Transfer learning of five categories of pictures based on VGg
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
Use of list - addition, deletion, modification and query
Vite configure proxy proxy to solve cross domain
41. The first missing positive number
C1 notes [task training part 2]
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
On the method of outputting the complete name of typeID from GCC
2021 Great Wall Cup WP
Implementation of image recognition code based on VGg convolutional neural network
Future usage details
Timestamp to formatted date
Kubernetes service discovery monitoring endpoints
JS implementation private attribute
Leak detection and vacancy filling (6)
Open source key component multi_ Button use, including test engineering
The ultimate experience, the audio and video technology behind the tiktok
Sword finger offer 03 Duplicate number in array
列表的使用-增删改查
Eigen learning summary