char[] byte[] string
C# byte 和 char 可以认为是等价的。但是在文本显示的时候有差异。
char 占两个字节,unicode字符
1、内存转换:
- char转化为byte:
public static byte[] charToByte(char c) {
byte[] b = new byte[];
b[] = (byte) ((c & 0xFF00) >> );
b[] = (byte) (c & 0xFF);
return b;
}
- byte转换为char:
public static char byteToChar(byte[] b) {
char c = (char) (((b[] & 0xFF) << ) | (b[] & 0xFF));
return c;
}
2、字符串转换
char[]转化为byte[]:
char[] cChar=new char[]{a,b,c,d,e};
byte[] byteData=Encoding.Default.GetBytes(cChar);
byte[]转化为char[]:
byte[] byteData=new byte[]{0x01,0x02,0x03,0x04,0x05};
char[] cChar=Encoding.ASCII.GetChars(byteData);
string类型转成byte[]:
byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str );
byte[]转成string:
string str = System.Text.Encoding.Default.GetString ( byteArray );
string类型转成ASCII byte[]:
byte[] = new byte[]{ 0x30,0x31}; // "01"
byte[] byteArray = System.Text.Encoding.ASCII.GetBytes ( str );
ASCIIbyte[]转成string:
byte[] = new byte[]{ 0x30, 0x31}; // "01"
string str = System.Text.Encoding.ASCII.GetString ( byteArray );
string 转换成 Char[]
string ss = "我爱你,中国";
char[] cc = ss.ToCharArray();
Char[] 转换成string
string s = new string(cc);
byte[] 与 string 之间的装换
byte[] bb = Encoding.UTF8.GetBytes(ss);
string s = Encoding.UTF8.GetString(bb);
char[] byte[] string的更多相关文章
- 对bit、byte、TByte、Char、string、进制的认识
在学校老师就教1byte = 8bit,一个Byte在内存中占8个房间.每个房间都有门牌号.找到内存中的内容就找门牌号,寻址什么的,虽然在听,但是脑袋里一头雾水,到现在只知道会用就行,但原理也不是那么 ...
- Java之byte、char和String类型相互转换
package basictype; /** * byte.char和String类型相互转换 */ public class CHJavaType { public static void main ...
- C#中char[]与string之间的转换;byte[]与string之间的转化
目录 1.char[]与string之间的转换 2.byte[]与string之间的转化 1.char[]与string之间的转换 //string 转换成 Char[] string str=&qu ...
- 探究 C# 中的 char 、 string(一)
目录 探究 C# 中的 char . string(一) 1. System.Char 字符 2. 字符处理 3. 全球化 4. System.String 字符串 4.1 字符串搜索 4.2 字符串 ...
- Cstring转char、string、int等数据类型的方法(转载)
Cstring转char.string.int等数据类型的方法 (-- ::) 转载 标签: 杂谈 分类: VC CString 转char * CString cstr; char *p = (LP ...
- string to char* and char* to string 玩转 String 和 Char*
char 类型是c语言中常见的一个数据类型,string是c++中的一个,它的定义为 Strings are objects that represent sequences of character ...
- 【C++】int、const char*、char*、char、string之间的转换
#include "stdafx.h" #include<string> #include<vector> #include<iostream> ...
- C++ 中int,char,string,CString类型转换
1. c++中string到int的转换 1) 在C标准库里面,使用atoi: #include <cstdlib> #include <string> std::stri ...
- C++ char*,const char*,string的相互转换
1. string转const char* string s ="abc";constchar* c_s = s.c_str(); 2. const char*转string ...
随机推荐
- [转帖]推荐一款比 Find 快 10 倍的搜索工具 FD
推荐一款比 Find 快 10 倍的搜索工具 FD https://www.hi-linux.com/posts/15017.html 试了下 很好用呢. Posted by Mike on 2018 ...
- Linux学习-防火墙-Selinux-配置本地YUM源
关闭防火墙并设置开机不启动 systemctl status firewalld.service #查看firewalld状态systemctl stop firewalld #关闭systemctl ...
- c#动态类转json,再由json转xml
直接上代码了,多说无意了. using System; using System.Collections; using System.Collections.Generic; using System ...
- win10+aconda+pytorch
1.需要建立项目的运行环境,每个项目应用的框架不用,所以对于每个项目分别用运行环境不会造成管理上的混乱以及应用上的冲突 2.建立项目运行环境: a.用管理员身份运行anconda prompt 创建c ...
- iOS核心动画(基础篇)
Core Animation相关内容基本介绍 此框架把屏幕上的内容组合起来,这个内容被分解成图层,放到图层树中,这个树形成了你能在应用程序看到的内容的基础 图层在iOS中就是CALayer类 当我们创 ...
- SAS学习笔记59 OPTIONS系统选项
带VALUE选项的OPTIONS过程将指定选项的值.范围及该值如何设置的信息打印到日志窗口 在日志窗口打印的输出如下图所示 将GETOPTION函数作为%SYSFUNC宏函数的参数,从而获取系统选项设 ...
- SpringCloudConfig相关配置简介、使用、整合Eureka
目的: 1.SpringCloud Config简介 2.Config Server基本使用 3.Config Client基本使用 4.Config整合Eureka 5.Config配置搜索路径 S ...
- docker-compose 单机容器编排
docker-compose用来在单机上编排容器(定义和运行多个容器,使容器能互通) docker-compose将所管理的容器分为3层结构:project service container d ...
- Lucene BooleanQuery中的Occur.MUST与Occur.Should
https://www.cnblogs.com/weipeng/archive/2012/04/18/2455079.html 1. 多个MUST的组合不必多说,就是交集 2. MUST和SH ...
- WPF窗体动态效果
在浏览网页的时候,发现现在很多网页都采用这种效果.看起来很炫. 效果如下: 已经实现很久了,一直没写出来.今天突然想到,写出来分享一下 原理比较简单,就是在Window里面放一个MediaElemen ...