在c#中将文本转换为二进制 [英] convert text to binary in c #

查看:194
本文介绍了在c#中将文本转换为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在c#中将文本转换为二进制文件,提前感谢帮助或一些示例。

解决方案

这个问题毫无意义。所有文件都是二进制文件,包括文本文件。



通常,对象或可执行文件称为二进制。并且代码以文本文件的形式编写,这些文件称为源代码。从这个意义上说,编译(编译和链接)确实从文本文件中生成了二进制文件。但它与转换或类似的东西无关。



-SA


我想你可能意味着像

  byte  [] binary = System.Text.Encoding.Unicode .GetBytes(yourString); 



根据您的具体要求,您可能需要与Unicode不同的编码。

要反转过程(即从字节中取回你的字符串),使用

  string  yourString = System.Text.Encoding.Unicode .GetString(二进制); 


您好


您可以在下面的帖子中查看一些示例



将字符串转换为二进制和上手 [ ^ ]

I need to convert text to binary in c #, appreciate the help or some example thanks in advance.

解决方案

This question makes no sense at all. All files are binary, including "text" files.

Very often, the object or executable files are called "binary". And the code is written in the form of text files, these files are called "source code". In that sense, compilation (compilation and linking) really produced "binary" files from "text" files. But it has nothing to do with "conversion" or something like that.

—SA


I guess you could mean something like

byte[] binary = System.Text.Encoding.Unicode.GetBytes(yourString);


Depending on your exact requirements, you may need a different encoding than Unicode.
To reverse the process (i.e. get your string back from the bytes), use

string yourString = System.Text.Encoding.Unicode.GetString(binary);


Hi
You can view few of the samples in below post

convert string to binary and overhand[^]


这篇关于在c#中将文本转换为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆