当前位置:网站首页>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
边栏推荐
- Operation of 2022 mobile crane driver national question bank simulation examination platform
- MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
- 102. Sequence traversal of binary tree
- Classification of cifar100 data set based on convolutional neural network
- 2021 Great Wall Cup WP
- 41. 缺失的第一个正数
- MySQL_01_简单数据检索
- Tell the truth of TS
- This point in JS
- 一些问题一些问题一些问题一些问题
猜你喜欢
随机推荐
列表的使用-增删改查
Future usage details
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
587. Install fence / Sword finger offer II 014 Anagrams in strings
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
关于gcc输出typeid完整名的方法
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
QTableWidget使用讲解
92. 反转链表 II-字节跳动高频题
.105Location
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
k8s之实现redis一主多从动态扩缩容
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
JS high frequency interview questions
YOLOv4剪枝【附代码】
92. Reverse linked list II byte skipping high frequency question
C1小笔记【任务训练篇一】
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
1217_ Generating target files using scons