最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

C#字节数组(byte[])和字符串相互转换

互联网 admin 1浏览 0评论

C#字节数组(byte[])和字符串相互转换

转换过程主要使用到System.Text.Encoding命名空间下的类

1. 字符串转换成字节数组byte[]:

string str = "This is test string";
byte[] byteArray = System.Text.Encoding.Default.GetBytes(str);

2.字节数组换成字符串:

byte[] byteArray = 通过某种方式获取到的字节数组
string str = System.Text.Encoding.Default.GetString(byteArray);

如果需要其他编码可以使用如:System.Text.UTF8Encoding class、System.Text.UnicodeEncoding class等

.html

C#字节数组(byte[])和字符串相互转换

转换过程主要使用到System.Text.Encoding命名空间下的类

1. 字符串转换成字节数组byte[]:

string str = "This is test string";
byte[] byteArray = System.Text.Encoding.Default.GetBytes(str);

2.字节数组换成字符串:

byte[] byteArray = 通过某种方式获取到的字节数组
string str = System.Text.Encoding.Default.GetString(byteArray);

如果需要其他编码可以使用如:System.Text.UTF8Encoding class、System.Text.UnicodeEncoding class等

.html

发布评论

评论列表 (0)

  1. 暂无评论