将文件转换为Ascii. [英] Converting a file to Ascii.

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

问题描述

我想将任何类型的文件转换为ASCII并将其显示在文本框中.我到处都是Google,没有运气! :confused:任何帮助将不胜感激!

这就是我正在从事的工作:

将myFile设置为新的System.IO.FileInfo(C:\ Test.exe)
将myStream昏暗为System.IO.FileStream = myFile.OpenRead()
将myFileLength变暗为long = myStream.Length
将昏暗的myAscii(myLength-1)作为字节

myStream.Read(myAscii,0,myFileLength)
昏暗的A字节= Convert.ToString(myAscii(0))
TextBox1.Text = A

这只给了我1个ASCII码.例如23.它不会一直读取文件到最后.我什至不确定这是否是最好的方法.我还在学习! (如果您现在才刚刚阅读此问题,请遍历所有评论.您可能会发现它们有点有趣(但不多!),因为到目前为止我完全想念它们!再次抱歉.它只是其中之一那些日子.

最后,阅读完所有评论后,我正在编辑我的问题,就像我早就应该做的一样!我想做一个循环,将ALL ASCII读取到文件末尾,并在上述代码的文本框中显示它们.任何人都可以提供帮助吗?

I would like to convert a file of any type to ASCII and display it in a textbox. I Googled everywhere with no luck! :confused: Any assistance would be greatly appreciated!

This is what I am working on:

Dim myFile As New System.IO.FileInfo(C:\Test.exe)
Dim myStream As System.IO.FileStream = myFile.OpenRead()
Dim myFileLength As Long = myStream.Length
Dim myAscii(myLength - 1) As Byte

myStream.Read(myAscii, 0, myFileLength)
Dim A As Byte = Convert.ToString(myAscii(0))
TextBox1.Text = A

This only gives me 1 ASCII code; 23 for example. It does not keep reading the file to the end. I''m not even sure if this is the best method. I''m still learning! (If you''ve just read this question now, go through all the comments. You may find them a bit amusing (but not much!) because I completely missed them until now! Sorry again. It''s just been one of those days.

And finally, after reading all the comments I''m editing my question, like I should have done a long time ago! I would like to make a loop to read ALL ASCII to the end of the file and display them in a textbox in the above code. Can anyone assist?

推荐答案

那么,您的意思是想读取字节数据,并将其作为十进制数字列表查看? File.ReadAllBytes将为您提供一个字节数组,然后您可以使用字符串生成器和foreach对其进行迭代,并构建数字列表. ASCII是编码文本的较旧方法,如果您想要数据的十六进制表示形式,那么您将在谈论十六进制,但是就目前而言,您只想查看数据.您还可以显示数据的ASCII表示形式,大多数十六进制编辑器都这样做,但是每个数字只能是一个字符,而不是数字本身.
So what you mean is that you want to read the byte data, and view it as a list of decimal numbers ? File.ReadAllBytes will give you a byte array, then you can use a string builder and foreach to iterate over that, and build your list of numbers. ASCII is the older way of encoding text, if you wanted hexadecimal representations of the data, then you''d be talking about hex, but as it stands, you just want to view the data. You CAN also show the ASCII representation of the data, most hex editors do that, but that would so a single character for each number, not the numbers themselves.


您的标签几乎没有用您如何做到这一点的想法.您所说的"ASCII"是什么意思?您所说的任何类型"是什么意思?例如,如何将位图转换为文本? PDF文件?您需要根据您的意思定义业务规则,除非您不表达自己的意思,否则这听起来像是一项非常复杂的任务.
Your tags leave us with little idea of how you''re doing this. What do you mean by ''ASCII'' ? What do you mean by ''any type'' ? How would you convert a bitmap, to text, for example ? A PDF ? You need to define business rules for what you mean, and unless you don''t mean what you said, it sounds like a pretty complex task.


我感谢您的快速响应.感谢您澄清的信息.抱歉,不清楚.我是VB新手.

基本上,我想将文件(.jpeg,.mp3,.avi,.exe等)转换为ASCII代码.

例如,以Mp3为例.

我将其视为:65 122 205 36 101

甚至像你所说的那样;逐位读取二进制文件,并将每个位转换为ASCII.

我已经搜索了Google一百万次,但找不到我想要的东西!
I appreciate the quick response. Thanks for the message to clarify. Sorry for being unclear. I''m new to VB.

Basically, I would like to convert a file (.jpeg, .mp3, .avi, .exe, etc.) to ASCII code.

Let''s say an Mp3 for example.

I would to view it as: 65 122 205 36 101

Or even like you stated; read a binary file bit by bit and convert each bit to ASCII.

I''ve searched Google a million times and can''t quite find what I''m looking for!


这篇关于将文件转换为Ascii.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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