c#中将整数转化为字符串_在C#中将字符串转换为字节数组
c#中将整数转化为字符串
Prerequisite: How to declare and use byte[] in C#?
先决条件: 如何在C#中声明和使用byte []?
C#中的字符串到字节数组的转换 (String to Byte Array Conversion in C#)
In C#, it is possible that a string can be converted to a byte array by using Encoding.ASCII.GetBytes() method, it accepts a string as a parameter and returns a byte array.
在C#中, 可以使用Encoding.ASCII.GetBytes()方法将字符串转换为字节数组 ,它接受字符串作为参数并返回字节数组。
Note: In C#, the string contains two bytes per character; the method converts it into 1 byte. Still, sometimes it is possible to lose the data.
注意:在C#中,字符串每个字符包含两个字节;每个字符包含两个字节。 该方法将其转换为1个字节。 但是,有时仍可能会丢失数据。
Syntax:
句法:
Method Encoding.ASCII.GetBytes() contains various overloaded methods, here we are using the following method type...
方法Encoding.ASCII.GetBytes()包含各种重载方法,这里我们使用以下方法类型...
byte[] Encoding.ASCII.GetBytes(String_Object);
Example:
例:
This example contains a constant string and converting it to byte[]
本示例包含一个常量字符串,并将其转换为byte []
using System;
using System.Text;
namespace Test
{class Program
{static void Main(string[] args)
{string str = "Hello World! I am [email protected]";
//reading all characters as byte and storing them to byte[]
byte[] barr = Encoding.ASCII.GetBytes(str);
//printing characters with byte values
for(int loop =0; loop<barr.Length-1; loop++)
{Console.WriteLine("Byte of char \'" + str[loop] + "\' : " + barr[loop]);
}
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
Byte of char 'H' : 72
Byte of char 'e' : 101
Byte of char 'l' : 108
Byte of char 'l' : 108
Byte of char 'o' : 111
Byte of char ' ' : 32
Byte of char 'W' : 87
Byte of char 'o' : 111
Byte of char 'r' : 114
Byte of char 'l' : 108
Byte of char 'd' : 100
Byte of char '!' : 33
Byte of char ' ' : 32
Byte of char 'I' : 73
Byte of char ' ' : 32
Byte of char 'a' : 97
Byte of char 'm' : 109
Byte of char ' ' : 32
Byte of char 'I' : 73
Byte of char 'n' : 110
Byte of char 'c' : 99
Byte of char 'l' : 108
Byte of char 'u' : 117
Byte of char 'd' : 100
Byte of char 'e' : 101
Byte of char 'H' : 72
Byte of char 'e' : 101
Byte of char 'l' : 108
Byte of char 'p' : 112
Byte of char '@' : 64
Byte of char '1' : 49
Byte of char '2' : 50
Byte of char '3' : 51
翻译自: https://www.includehelp.com/dot-net/convert-string-to-byte-array-in-c-sharp.aspx
c#中将整数转化为字符串
c#中将整数转化为字符串_在C#中将字符串转换为字节数组相关推荐
- scala 字符串转换数组_如何在Scala中将十六进制字符串转换为字节数组?
scala 字符串转换数组 Hex String in Scala denotes value in hexadecimal number system i.e. base 16 number sys ...
- 在C#中将字符串转换为字节数组
本文翻译自:Converting string to byte array in C# I'm converting something from VB into C#. 我正在将某些东西从VB转换为 ...
- java字符串转换成字节数组_将Java字符串转换为字节数组
我有一个要加密的字节数组,然后转换为字符串,以便可以传输. 当我收到字符串时,我必须将字符串转换回字节数组,以便可以对其进行解密. 我检查了接收到的字符串是否与发送的字符串(包括长度)匹配,但是当我使 ...
- c#将字符串转换为数组,在C#中将字符串转换为字节数组
先决条件:如何在C#中声明和使用byte []? C#中的字符串到字节数组的转换 在C#中,可以使用Encoding将字符串转换为字节数组.方法,它接受字符串作为参数并返回字节数组.ASCII.Get ...
- 读入的字节都写入字节数组中_使用Java将文件读入字节数组的7个示例
读入的字节都写入字节数组中 嗨,大家好,Java程序员经常在现实世界中遇到编程问题,他们需要将文件中的数据加载到字节数组中,该文件可以是文本文件或二进制文件. 一个示例是将文件的内容转换为String ...
- JavaScript:实现将 base64 字符串转换为字节数组算法(附完整源码)
JavaScript:实现将 base64 字符串转换为字节数组算法 function base64ToBuffer (b64) {// The base64 encoding uses the fo ...
- 递归 反转字符串_使用递归反转字符串
递归 反转字符串 1.简介 在本文中,您将学习如何使用递归方法来反转字符串. 第一个程序是反转字符串,第二个程序将读取用户的输入. 在之前的文章中,我已经展示了如何不使用任何内置函数来反转字符串,以及 ...
- c替换指定位置字符串_【JavaScript】字符串
字符串 字符串可以是插入到引号中的任何字符.你可以使用单引号或双引号: var carname = "MI"; 可以使用索引位置来访问字符串中的每个字符: var characte ...
- python如何连续查找字符串_在另一个字符串Python中多次查找字符串
我尝试使用Python的预定义函数(如find和index)查看一个字符串是否存在于另一个字符串中..在 现在我的函数有两个字符串作为参数,一个是我们要搜索的字符串,另一个字符串是我们在第一个字符串中 ...
最新文章
- Bzoj2780: [Spoj]8093 Sevenk Love Oimaster
- Linux系统安装DNS域名解析服务
- 【Linux】一步一步学Linux——skill命令(143)
- 02-HTTP的请求方法以及响应状态码
- String与string的区别
- php模拟论坛,模仿OSO的论坛(二)
- 腾讯开源业界首个云原生标准的一站式微服务管理框架Femas
- Oracle——distinct的用法
- 实战Javascript:结合电商主界面实现轮播图和倒计时秒杀
- Redis12-事件
- python pip下载安装一半退出_【Python】pip安装numpy安装到一半失败解决办法
- 推荐阅读投资理财经典55本
- CNC编程工程师如何炼成?要哪些必备技能?
- win7怎么把计算机图标下的箭头掉,Win7桌面图标有小箭头怎么去掉?Win7去除桌面图标小箭头的方法...
- 如何用计算机设计衣服,如何用电脑设计服装
- window7系统为什么老是弹出交互式服务检测
- 学会IDEA REST Client后,postman就可以丢掉了...
- linux猜数字代码,Shell脚本实现猜数字游戏
- 2021-04-19-记录学习linux
- 预测学习应用于机器人之Unsupervised Learning for Physical Interaction through Video Prediction