// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Text.RegularExpressions; namespace E { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private const string PREFIX = @"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}\viewkind4\uc1\pard\lang1033\f0\fs17 "; private const string SUFFIX = @"\par}"; private string Html2Rtf(string html) { return PREFIX + Regex.Replace(html.Replace("
", @"\par" + Environment.NewLine), "()([^<]*)()", @"{\b $2}") + SUFFIX; } private void Button1Click(object sender, EventArgs e) { string html = tb.Text; string rtf = Html2Rtf(html); rtb.Rtf = rtf; } } }