在StreamWriter中设置文本格式 [英] format text in a StreamWriter
问题描述
是否可以在StreamWriter中格式化文本
Is it posible to format text in a StreamWriter
StreamWriter sWriter = new StreamWriter(path);
sWriter.WriteLine("Text");
我需要格式化文本",可能会更改颜色和字体大小以及其他内容.
I need to format "Text" maybe change color and the font size and others
推荐答案
如果要在文件中包括格式化信息,则可以选择:
If you want to include formatting information in your file then you may either choose:
- 文档格式的预定义标准,例如
RTF
,HTML
或PDF
.
或 - 您拥有手工制作的文件格式.
- A predefined standard for document format, e.g.
RTF
,HTML
orPDF
.
or - You own hand crafted file format.
如果选择路线(1),则StreamWriter
仅适用于文本文件格式,例如RTF
或HTML
(对于PDF
文件,您需要BinaryWriter).
如果选择路线(2),则格式属性规格由您决定...
无论您选择什么,都需要根据文档格式规范对格式设置属性(例如字体)进行编码(例如,参见富文本格式格式(RTF)1.5版规范" [ ^ ]和简单的RTF教程" [
If you choose the route (1) then you the StreamWriter
is suitable only for text file formats, like RTF
or HTML
(you need a BinaryWriter for a PDF
file).
If you choose the route (2) then the formatting attributes specifications are up to you...
Whatever is your choice, you need to encode the formatting attributes (e.g. font) according with the document format specifications (see, for instance "Rich Text Format (RTF) Version 1.5 Specification"[^] and "A simple RTF tutorial"[^]).
这篇关于在StreamWriter中设置文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!