RTF files are not unfamiliar, but RTF file encoding, decoding is very difficult, because the RTF file is rich in text format, that is, in addition to the text content in the file, but also contains text format information, and this information does not like the subsequent docx, such as the use of XML to isolate the format and content, so decoding is difficult.
Some instrument data reports are exported in RTF format because RTF can be edited using WordPad, and the WordPad program is installed by default on Windows systems, so the output RTF file is easy to read and write.
Parsing RTF files, it is difficult to start from decoding, but can rely on the basic functionality of Windows to achieve rich text content acquisition, in particular, rely on the WinForm class library to read RTF file content, of course, this way can read the text content, picture, table style will be ignored.
The following is the sample code:
RichTextBox Rtbox = new RichTextBox (); string s = File.readalltext (fileName); Rtbox.rtf = s; string plaintext = Rtbox.text; return plaintext;
C # Instrument data file parsing-rtf file