当前位置:网站首页>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
边栏推荐
- 92. Reverse linked list II byte skipping high frequency question
- C1小笔记【任务训练篇二】
- QT modification UI does not take effect
- 122. The best time to buy and sell stocks II - one-time traversal
- Halo open source project learning (II): entity classes and data tables
- Gaode map search, drag and drop query address
- Detailed deployment of flask project
- Double pointer advanced -- leetcode title -- container with the most water
- Utilisation de la liste - Ajouter, supprimer et modifier la requête
- 2022 tea artist (primary) examination simulated 100 questions and simulated examination
猜你喜欢

440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题

EasymodbusTCP之clientexample解析

MySQL进阶之索引【分类,性能分析,使用,设计原则】

Summary of common SQL statements

Kubernetes 服务发现 监控Endpoints

Auto.js 自定义对话框

Hcip fifth experiment

云原生虚拟化:基于 Kubevirt 构建边缘计算实例

Go file operation

2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
随机推荐
【Appium】通过设计关键字驱动文件来编写脚本
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
470. Rand10() is implemented with rand7()
Amount input box, used for recharge and withdrawal
Encapsulate a timestamp to date method on string prototype
MySQL_01_简单数据检索
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
1217_ Generating target files using scons
[appium] write scripts by designing Keyword Driven files
Future usage details
Cross domain settings of Chrome browser -- including new and old versions
122. 买卖股票的最佳时机 II-一次遍历
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]
Commonly used functions -- spineros:: and spineros::)
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
Vite configure proxy proxy to solve cross domain
ES6
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Flask项目的部署详解