Cleaning up RTF text

后端 未结 4 1145
谎友^
谎友^ 2021-01-02 06:38

I\'d like to take some RTF input and clean it to remove all RTF formatting except \\ul \\b \\i to paste it into Word with minor format information.

The command used

4条回答
  •  醉话见心
    2021-01-02 07:13

    Regex it, it wont parse absolutely everything correctly (tables for example) but does the job in most cases.

    string unformatted = Regex.Replace(rtfString, @"\{\*?\\[^{}]+}|[{}]|\\\n?[A-Za-z]+\n?(?:-?\d+)?[ ]?", "");
    

    Magic =)

提交回复
热议问题