用格式将文本写入记事本 [英] write text to notepad with format

查看:87
本文介绍了用格式将文本写入记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

我正在从具有4列的数据库中获取一些数据

我想通过创建如下相同的列数来在记事本文件中获取它

我还想设置其固定大小的宽度

Dear all

I am fetching some data from database having 4 columns

I want to fetch it in notepad file by creating same no of columns as follows

I also want set its width of fix size

colmn1          column2              column3             column4
------         ---------                -------          ---------
------         ---------               --------          --------

------         --------                 --------         ----------

推荐答案

如果您指的是记事本可以读取的文件,那么您指的是文本文件:即扩展名为".TXT"的文件.
.TXT没有固定宽度的概念,因此,如果要布局文件内容,则需要以结构化的方式写入文件.幸运的是,.NET提供了可以执行此操作的string.Format以及Write和WriteLine方法的格式字符串参数. 您需要在格式字符串中提供的是您要输出的完整固定宽度格式-该格式将根据您的数据类型而有所不同.
例如,如果要输出int"i"和字符串"s"作为固定格式数据:

If you mean a file that notepad can read, then you mean a text file: i.e. a file with teh extension ".TXT"
.TXT does not have a concept of fixed widths, so if you want to lay out the file content then you need to write to teh file in a structured manner. Fortunately, .NET provides string.Format which can do this, as well as the format string parameter to teh Write and WriteLine methods.
What you need to provide in the format string is the complete fixed width format that you want to output - which will vary depending on your data types.
For example, if you want to output an int "i" and a string "s" as fixed format data:

int i = 12;
string s = "ABC";
myStream.WriteLine("{0,6}  {1,10}", i, s);


这篇关于用格式将文本写入记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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