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#中将字符串转换为字节数组相关推荐

  1. scala 字符串转换数组_如何在Scala中将十六进制字符串转换为字节数组?

    scala 字符串转换数组 Hex String in Scala denotes value in hexadecimal number system i.e. base 16 number sys ...

  2. 在C#中将字符串转换为字节数组

    本文翻译自:Converting string to byte array in C# I'm converting something from VB into C#. 我正在将某些东西从VB转换为 ...

  3. java字符串转换成字节数组_将Java字符串转换为字节数组

    我有一个要加密的字节数组,然后转换为字符串,以便可以传输. 当我收到字符串时,我必须将字符串转换回字节数组,以便可以对其进行解密. 我检查了接收到的字符串是否与发送的字符串(包括长度)匹配,但是当我使 ...

  4. c#将字符串转换为数组,在C#中将字符串转换为字节数组

    先决条件:如何在C#中声明和使用byte []? C#中的字符串到字节数组的转换 在C#中,可以使用Encoding将字符串转换为字节数组.方法,它接受字符串作为参数并返回字节数组.ASCII.Get ...

  5. 读入的字节都写入字节数组中_使用Java将文件读入字节数组的7个示例

    读入的字节都写入字节数组中 嗨,大家好,Java程序员经常在现实世界中遇到编程问题,他们需要将文件中的数据加载到字节数组中,该文件可以是文本文件或二进制文件. 一个示例是将文件的内容转换为String ...

  6. JavaScript:实现将 base64 字符串转换为字节数组算法(附完整源码)

    JavaScript:实现将 base64 字符串转换为字节数组算法 function base64ToBuffer (b64) {// The base64 encoding uses the fo ...

  7. 递归 反转字符串_使用递归反转字符串

    递归 反转字符串 1.简介 在本文中,您将学习如何使用递归方法来反转字符串. 第一个程序是反转字符串,第二个程序将读取用户的输入. 在之前的文章中,我已经展示了如何不使用任何内置函数来反转字符串,以及 ...

  8. c替换指定位置字符串_【JavaScript】字符串

    字符串 字符串可以是插入到引号中的任何字符.你可以使用单引号或双引号: var carname = "MI"; 可以使用索引位置来访问字符串中的每个字符: var characte ...

  9. python如何连续查找字符串_在另一个字符串Python中多次查找字符串

    我尝试使用Python的预定义函数(如find和index)查看一个字符串是否存在于另一个字符串中..在 现在我的函数有两个字符串作为参数,一个是我们要搜索的字符串,另一个字符串是我们在第一个字符串中 ...

最新文章

  1. Bzoj2780: [Spoj]8093 Sevenk Love Oimaster
  2. Linux系统安装DNS域名解析服务
  3. 【Linux】一步一步学Linux——skill命令(143)
  4. 02-HTTP的请求方法以及响应状态码
  5. String与string的区别
  6. php模拟论坛,模仿OSO的论坛(二)
  7. 腾讯开源业界首个云原生标准的一站式微服务管理框架Femas
  8. Oracle——distinct的用法
  9. 实战Javascript:结合电商主界面实现轮播图和倒计时秒杀
  10. Redis12-事件
  11. python pip下载安装一半退出_【Python】pip安装numpy安装到一半失败解决办法
  12. 推荐阅读投资理财经典55本
  13. CNC编程工程师如何炼成?要哪些必备技能?
  14. win7怎么把计算机图标下的箭头掉,Win7桌面图标有小箭头怎么去掉?Win7去除桌面图标小箭头的方法...
  15. 如何用计算机设计衣服,如何用电脑设计服装
  16. window7系统为什么老是弹出交互式服务检测
  17. 学会IDEA REST Client后,postman就可以丢掉了...
  18. linux猜数字代码,Shell脚本实现猜数字游戏
  19. 2021-04-19-记录学习linux
  20. 预测学习应用于机器人之Unsupervised Learning for Physical Interaction through Video Prediction

热门文章

  1. linux下qq怎么截图,ubuntu 12.04使用QQ截图安装教程
  2. aix升级新安装oracle,安装Oracle 11gR2 AIX 5.3 升级到TL11的一些小记录
  3. 查找指定日期数据所在分区数据
  4. RHEL7 修改SSH默认端口
  5. PHP学习方向-进阶2(三) 1
  6. 金融行业 | 电子银行系统性能优化解决方案
  7. django 1.8 官方文档翻译:2-1-1 模型语法
  8. Java 解决采集UTF-8网页空格变成问号乱码
  9. nagios客户端nrped服务方式启动脚本
  10. [置顶] 任务三 主题、样式