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++中多态是面向对象设计思想的重要特性,同名具有不同功能函数,该函数调用过程执行不同的功能.多态的原理是通过一张虚函数表(Virtual Table)实现的.动多态会牺牲一些空间和效率来最终实现动态 ...
- vue中指令绑定的v-if逻辑结构
<!-- if判断 --> <div id="app2"> <p v-if="seen"> <!-- 给p标签绑定指令 ...
- Django REST Framework批量更新rest_framework_extensions
Django REST framework 是一套基于Django框架编写RESTful风格API的组件. 其中mixins配合viewsets能极其方便简化对数据的增删改查, 但本身并没有对数据的批 ...
- 【IDEA使用技巧】(3) —— IntelliJ IDEA Maven配置
1.IntelliJ IDEA Maven配置 1.1. Maven介绍与下载 Maven是一个项目管理工具,使用它能对Java项目中的jar包进行管理与项目构建,很好地解决了传统项目使用导包的方式管 ...
- Microsoft.AspNet.Identity 自定义使用现有的表—登录实现,aspnet.identity
Microsoft.AspNet.Identity是微软新引入的一种membership框架,也是微软Owin标准的一个实现.Microsoft.AspNet.Identity.EntityFrame ...
- redis连接相关命令
命令名称:echo 语法:echo message 功能: 打印一个特定的信息message,测试时使用. 返回值: message自身 命令名称:ping 语法:ping 功能: 使用客户端向red ...
- Online Hard Example Mining 理解
Definition: Online Hard Example Mining (OHEM) is a way to pick hard examples with reduced computatio ...
- Linux ass2srt
Linux ass2srt bash script #! /usr/bin/env bash ] then echo "USAGE: $0 <directory> <fro ...
- php-sql-server-2017
Download the Microsoft Drivers for PHP for SQL Server https://docs.microsoft.com/en-us/sql/connect/p ...
- kubernetes第六章--如何访问pod