用格式将文本写入记事本

编程入门 行业动态 更新时间:2024-10-27 04:34:06
本文介绍了用格式将文本写入记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的所有人 我正在从具有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);

更多推荐

用格式将文本写入记事本

本文发布于:2023-11-11 11:07:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:记事本   文本   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!