How to convert a string to RTF in C#?

前端 未结 7 1636
小鲜肉
小鲜肉 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:18

    Below is an ugly example of converting a string to an RTF string:

    class Program
    {
        static RichTextBox generalRTF = new RichTextBox();
    
        static void Main()
        {
            string foo = @"Européen";
            string output = ToRtf(foo);
            Trace.WriteLine(output);
        }
    
        private static string ToRtf(string foo)
        {
            string bar = string.Format("!!@@!!{0}!!@@!!", foo);
            generalRTF.Text = bar;
            int pos1 = generalRTF.Rtf.IndexOf("!!@@!!");
            int pos2 = generalRTF.Rtf.LastIndexOf("!!@@!!");
            if (pos1 != -1 && pos2 != -1 && pos2 > pos1 + "!!@@!!".Length)
            {
                pos1 += "!!@@!!".Length;
                return generalRTF.Rtf.Substring(pos1, pos2 - pos1);
            }
            throw new Exception("Not sure how this happened...");
        }
    }
    
    0 讨论(0)
提交回复
热议问题