生成ASCII并创建文件 [英] Generating ASCII and Creating a File

查看:864
本文介绍了生成ASCII并创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我试图通过FIRST输入十进制值生成ASCII字符,然后创建一个外部文件来保存字符 。有人可以告诉我如何做到这一点。我对Filestream Class有很多问题,一个错误接着另一个。这非常复杂。

Hello,
I am trying to generate ASCII Characters by FIRST entering the decimal value and then creating a external file to save the Characters. Can someone please show me how to do this. I having many problems with the Filestream Class, one error after the other. This is very complicated.

推荐答案

这一点都不复杂! :笑:



ASCII只是字节值,根据字符集解释为字符: http://www.charstable.com/_site_media/ascii/chars-table-landscape.jpg [ ^ ]

因此,如果您的用户(或您的代码) )为每个字符输入十进制值,您只需将其转换为字节值,将其插入字节集合并将这些值直接写入您的文件。



It's not at all complicated! :laugh:

ASCII is just byte values which are interpreted as characters according to a character set: http://www.charstable.com/_site_media/ascii/chars-table-landscape.jpg[^]
So if your user (or your code) is entering decimal values for each character, all you have to do is convert that to a byte value, insert it into a collection of bytes and write those values direct to your file.

byte[] data = new byte[] {72, 101, 108, 108, 111, 13, 10};
File.WriteAllBytes(@"D:\Temp\MyFile.txt", data);



将文本Hello和换行符写入文件......


Will write the text "Hello" and a newline to the file...


这篇关于生成ASCII并创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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