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. 在windows 上自动重启 tomcat 的方法

    在windows 上自动重启 tomcat 的方法 实现思路: Windows 上监控tomcat 进程并且自动重启的脚本 一类是 定时重启 tomcat 一类是 监控并重启 写一个守护tomcat进 ...

  2. springboot aop的execution 表达式详解

    Aspectj切入点语法定义 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义切入点表达式  execu ...

  3. 搜素表脚本.vbs

    Set oFso = CreateObject("Scripting.FileSystemObject")dim path(30)dim name(30)'说明书表头有15列:补丁 ...

  4. Springboot 文件上传(带进度条)

    1. 相关依赖 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...

  5. Timeline Storyteller 现已加入自定义图表库

    前言 下载地址: https://store.office.com/en-us/app.aspx?assetid=WA104381136&sourcecorrid=328f5e2b-e973- ...

  6. HTML5+CSS3 loading 效果收集--转载

    用gif图片来做loading的时代已经过去了,它显得太low了,而用HTML5/CSS3以及SVG和canvas来做加载动画显得既炫酷又逼格十足.这已经成为一种趋势. 这里收集了几十个用html5和 ...

  7. 浏览器打开exe文件

    <win-r> regedit 打开注册表,然后自定义协议 自定义协议注册表.reg 打开后导入 Windows Registry Editor Version 5.00 [HKEY_CL ...

  8. markdown 基本语法(转载)

    最近感觉一直使用富文本编辑器写东西,感觉有点烦,所以就试着学习了一下简单的markdown编辑器的使用 原文地址:http://www.jianshu.com/p/815788f4b01d markd ...

  9. elk之elasticsearch(二)

    一.下载安装包:注意版本统一 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.zip wge ...

  10. js中级小知识5

    元素的属性 div.attributes是所有标签属性构成的数据集合 div.classList是所有class名构成的数组集合 在classList的原型链上可以看到add()和remove() 1 ...