Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / C#

Using Regular Expression for Parsing

Rate me:
Please Sign up or sign in to vote.
2.85/5 (4 votes)
16 Mar 2007CPOL 36.5K   264   21  
Derived currently supports RTF and HTML format
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SyntaxEngineClass;

namespace SyntaxEngineDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Close();
        }
        private bool FHasRtf = false; // �Ƿ�����Ѿ����ɵ�Rtf
        private bool FHasHtml = false; // �Ƿ�����Ѿ����ɵ�Html

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            FHasRtf = false;
            FHasHtml = false;
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            CSharpEngine vCSharpEngine;
            CSharpHighlight vCSharpHighlight;
            switch (((TabControl)sender).SelectedIndex)
            {
                case 1: //rtf
                    if (FHasRtf) return;
                    vCSharpEngine = new CSharpEngine();
                    vCSharpEngine.Analyze(textBox1.Text);
                    vCSharpHighlight = new CSharpHighlight(vCSharpEngine, new Font("Courier New", 10));
                    richTextBox1.Rtf = vCSharpHighlight.MakeRtf();
                    FHasRtf = true;
                    break;
                case 2: //html
                    if (FHasHtml) return;
                    vCSharpEngine = new CSharpEngine();
                    vCSharpEngine.Analyze(textBox1.Text);
                    vCSharpHighlight = new CSharpHighlight(vCSharpEngine, new Font("Courier New", 10));
                    webBrowser1.DocumentText = vCSharpHighlight.MakeHtml();
                    FHasHtml = true;
                    break;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
zswang

Comments and Discussions