Encoding类  表示字符编码

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

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace FileStreamTest
{
class Program
{
static void Main(string[] args)
{
string str = "Hello World!";
//将字符串转换成字节组
byte[] bytes = Encoding.Default.GetBytes(str);
foreach (byte b in bytes)
{
Console.Write(b+" ");
}
Console.WriteLine();
Console.ReadLine(); }
}
}

2.字节数组换成字符串

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace FileStreamTest
{
class Program
{
static void Main(string[] args)
{
byte[] bytes = { , , , , , , , , , , , };
//将字节组转换成字符串
string newStr = Encoding.Default.GetString(bytes);
Console.Write(newStr);
Console.ReadLine();
}
}
}

C#-----字节数组(byte[])和字符串相互转换的更多相关文章

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

    转换过程主要使用到System.Text.Encoding命名空间下的类 1. 字符串转换成字节数组byte[]: string str = "This is test string&quo ...

  2. C#中字节数组byte[]和字符串string类型的相互转换

    C#中字节数组byte[]和字符串string类型的相互转换: string转byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBy ...

  3. c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换

    字节数组byte[]与图片image之间的转化 字节数组转换成图片 public static Image byte2img(byte[] buffer) { MemoryStream ms = ne ...

  4. C#字节数组转换成字符串

    C#字节数组转换成字符串 如果还想从 System.String 类中找到方法进行字符串和字节数组之间的转换,恐怕你会失望了.为了进行这样的转换,我们不得不借助另一个类:System.Text.Enc ...

  5. 数组Byte [] 和 string 相互转换

    using System; using System.Collections.Generic; using System.Text; namespace NET.MST.Fourth.StringBy ...

  6. 字节数组byte[]和整型,浮点型数据的转换——Java代码

    近期在写C++ socket和java socket之间的通信程序,涉及到整数浮点数的传输.须要从字节数组还原数据,查了一些资料.总结例如以下 1.       整数和浮点数的机器表示 在机器内部.不 ...

  7. 文件读写(三)利用FileStream类操作字节数组byte[]、BinaryFormatter、内存流MemoryStream

    一.Stream类概述 在.NET Framework中,文件和流是有区别的.文件是存储在磁盘上的数据集,它具有名称和相应的路径.当打开一个文件并对其进行读/写时,该文件就称为流(stream).但是 ...

  8. Java基础知识强化之IO流笔记27:FileInputStream读取数据一次一个字节数组byte[ ]

    1. FileInputStream读取数据一次一个字节数组byte[ ]  使用FileInputStream一次读取一个字节数组: int read(byte[]  b) 返回值:返回值其实是实际 ...

  9. [.Net,C#]三类资源:流对象Stream,字节数组byte[],图片Image

    三类资源:流对象Stream,字节数组byte[],图片Image 关系:Stream<=>byte[],byte[]<=>Image Stream 与Image相互转化的媒介 ...

随机推荐

  1. Centos 使用Systemctl报Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)

    在使用centos7.4 安装服务的时候报错: Error getting authority: Error initializing authority: Error calling StartSe ...

  2. webapi 统一处理时间格式

    public class UnixDateTimeConvertor : DateTimeConverterBase { public override object ReadJson(JsonRea ...

  3. 从0移植uboot(五) _实现串口输出

    串口作为一种非常简单的通信方式,才是嵌入式系统调试的王道,通过设置串口输出,我们可以将程序运行的情况直接通过串口线输出到屏幕上,对于这种异常重要的功能,uboot原生就提供了支持,但为此我们需要做一些 ...

  4. mysql之表格的关联关系

    1.’基本模式有多对一,多对多,一对一.关联的两个基本组建为外键列和参照列 典型的多对一模式,很普遍,如部门表和员工表,即一个部门可以有多个员工. 对于多对多的模式,就需要建立中间表,将其转换为多对一 ...

  5. 进程间通信之——队列Queue

    队列是先进先出. from multiprocessing import Queue q = Queue(6) # 队列容纳上限 q.put(1) # 放到队列里面 q.put(2) q.put(3) ...

  6. Win10上使用VS2015编译Caffe2

    Caffe2的官网:https://caffe2.ai/ 1.下载.安装及相关准备 在Caffe2的官网点击"Get Started",即进入安装说明页面.官方还未提供编译好的bi ...

  7. Moving Tables---(贪心)

    Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...

  8. vue 中的数据绑定

    vue当中有个v-model, 是怎么实现的呢?其实是利用了$event. <div id="app"> <!-- 输入什么,就输出什么 --> <i ...

  9. SQL Server 索引自动组织维护

    公司的一个产品中的数据库,几个热点表因为主键和索引设计不合理,造成索引碎片过大,影响性能. 我尝试新建了一个索引碎片整理的定时任务,用于维护索引锁片和统计信息. 具体的过程如下: 本文原创,转发请表明 ...

  10. oracle日期格式化

    TO_CHAR(t.CAMERA_CREAT_TIME, 'YYYY-MM-DD HH24:MI:SS') as point_registerdate,TO_CHAR(t.CAMERA_MODIFY_ ...