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 ...
随机推荐
- c++无关类型指针的强制转换原理的分析和尝试
因最近看到大量的c类型指针强制转换,联系到c++的reinterpret_cast强制转换符,故总结一下. 先上图 由图中可以看出,先声明了一个结构体t与一个含有三个元素的数组num,接着声明一个指向 ...
- Go 参数传递
Go参数传递 在面试中,经常会被问起,这门语言的参数传递是值传递还是引用传递,当然,大部分情况下我们都会提前准备,有恃无恐,但还是希望能够精益求精嘛,所以针对Go语言来分析,Go传参是值传递还是引用传 ...
- 深度探索MySQL主从复制原理
深度探索MySQL主从复制原理 一 .概要 MySQL Replication (MySQL 主从复制) 是什么? 为什么要主从复制以及它的实现原理是什么? 1.1 MySQL 主从复制概念 MySQ ...
- Codeforces Round #568 Div. 2
没有找到这场div3被改成div2的理由. A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long ...
- redis订阅与发布系统
一.概述 1.redis通过publish.subscribe等命令实现了订阅与发布模式. 2.这个功能提供两种信息机制,分别是订阅/发布到频道和订阅/发布到模式. 二.频道的订阅与信息发送 1.re ...
- Java 二叉搜索树 实现和学习
/** * <html> * <body> * <P> Copyright 1994 JsonInternational</p> * <p> ...
- NEST explain
Elasticsearch 的相似度算法 被定义为检索词频率/反向文档频率, TF/IDF ,包括以下内容: 检索词频率 检索词在该字段出现的频率?出现频率越高,相关性也越高. 字段中出现过 5 次要 ...
- 谷歌浏览器解决ajax跨域问题
在用mui和H5+做混合开发,会利用HBuildx去真机调试,可真机调试总有问题所在,懂得人自然懂,而我们直接打开页面显示的只有一个静态的页面,是获取不到数据的在这里我想说的不是代码中利用jsonp, ...
- C++线程同步之临界区
#include <iostream> #include <windows.h> using namespace std; CRITICAL_SECTION cs; // Lo ...
- Jmeter学习笔记(九)——响应断言
Jmeter中又一个元件叫断言,用于检查测试中得到的响应数据等是否符合预期.断言又13种,目前在使用过程中使用到的是响应断言. 有时候请求成功了并不代表测试通过,还要看影响返回的内容是否符合预期的结果 ...