How to convert a string to RTF in C#?

前端 未结 7 1677
小鲜肉
小鲜肉 2020-11-29 09:16

Question

How do I convert the string \"Européen\" to the RTF-formatted string \"Europ\\\'e9en\"?

[TestMethod]
public void Convert_A_         


        
7条回答
  •  伪装坚强ぢ
    2020-11-29 10:00

    I know it has been a while, hope this helps..

    This code is working for me after trying every conversion code I could put my hands on:

    titleText and contentText are simple text filled in a regular TextBox

    var rtb = new RichTextBox();
    rtb.AppendText(titleText)
    rtb.AppendText(Environment.NewLine);
    rtb.AppendText(contentText)
    
    rtb.Refresh();
    

    rtb.rtf now holds the rtf text.

    The following code will save the rtf text and allow you to open the file, edit it and than load it back into a RichTextBox back again:

    rtb.SaveFile(path, RichTextBoxStreamType.RichText);
    

提交回复
热议问题