在StreamWriter中设置文本格式 [英] format text in a StreamWriter

查看:204
本文介绍了在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:
  1. 文档格式的预定义标准,例如RTFHTMLPDF.

  2. 您拥有手工制作的文件格式.
  1. A predefined standard for document format, e.g. RTF, HTML or PDF.
  2. or
  3. You own hand crafted file format.



如果选择路线(1),则StreamWriter仅适用于文本文件格式,例如RTFHTML(对于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屋!

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