当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

完成C#正则表达式测试器

输入正则表达式,测试文本,输出经表达式过滤的文本,第一个实用C#窗口程序,可用csc批处理程序直接编译

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;

    namespace RegexTester
    {
     ///
     /// Form1 的摘要说明。
     ///
     public class Form1 : System.Windows.Forms.Form
     {
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.OpenFileDialog openFileDialog1;
      private System.Windows.Forms.SaveFileDialog saveFileDialog1;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Label label4;
      private System.Windows.Forms.TextBox RegexTextBox;
      private System.Windows.Forms.GroupBox OptionsGroup;
      private System.Windows.Forms.CheckBox ECMAScriptChkBox;
      private System.Windows.Forms.CheckBox ExplicitCaptureChkBox;
      private System.Windows.Forms.CheckBox IgnoreCaseChkBox;
      private System.Windows.Forms.CheckBox MultiLineChkBox;
      private System.Windows.Forms.CheckBox RightToLeftChkBox;
      private System.Windows.Forms.CheckBox SingleLineChkBox;
      private System.Windows.Forms.CheckBox IgnorePatternWhiteSpaceChkBox;
      private System.Windows.Forms.Button OpenRegexButton;
      private System.Windows.Forms.Button SaveRegexButton;
      private System.Windows.Forms.TextBox InputTextBox;
      private System.Windows.Forms.TextBox ReplacementTextBox;
      private System.Windows.Forms.TextBox ResultTextBox;
      private System.Windows.Forms.Button TestRegaxButton;
      private System.Windows.Forms.Button ReplaceButton;
      private System.Windows.Forms.Button SplitButton;
      private System.Windows.Forms.Button MatchesButton;
      ///
      /// 必需的设计器变量。
      ///
      private System.ComponentModel.Container components = null;

      public Form1()
      {
       //
       // Windows 窗体设计器支持所必需的
       //
       InitializeComponent();

       //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }

      ///
      /// 清理所有正在使用的资源。
      ///
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null)
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }

      #region Windows 窗体设计器生成的代码
      ///
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      ///
      private void InitializeComponent()
      {
       this.label1 = new System.Windows.Forms.Label();
       this.RegexTextBox = new System.Windows.Forms.TextBox();
       this.OptionsGroup = new System.Windows.Forms.GroupBox();
       this.IgnorePatternWhiteSpaceChkBox = new System.Windows.Forms.CheckBox();
       this.SingleLineChkBox = new System.Windows.Forms.CheckBox();
       this.RightToLeftChkBox = new System.Windows.Forms.CheckBox();
       this.MultiLineChkBox = new System.Windows.Forms.CheckBox();
       this.IgnoreCaseChkBox = new System.Windows.Forms.CheckBox();
       this.ExplicitCaptureChkBox = new System.Windows.Forms.CheckBox();
       this.ECMAScriptChkBox = new System.Windows.Forms.CheckBox();
       this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
       this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
       this.OpenRegexButton = new System.Windows.Forms.Button();
       this.SaveRegexButton = new System.Windows.Forms.Button();
       this.label2 = new System.Windows.Forms.Label();
       this.InputTextBox = new System.Windows.Forms.TextBox();
       this.label3 = new System.Windows.Forms.Label();
       this.ReplacementTextBox = new System.Windows.Forms.TextBox();
       this.label4 = new System.Windows.Forms.Label();
       this.ResultTextBox = new System.Windows.Forms.TextBox();
       this.TestRegaxButton = new System.Windows.Forms.Button();
       this.ReplaceButton = new System.Windows.Forms.Button();
       this.SplitButton = new System.Windows.Forms.Button();
       this.MatchesButton = new System.Windows.Forms.Button();
       this.OptionsGroup.SuspendLayout();
       this.SuspendLayout();
       //
       // label1
       //
       this.label1.Location = new System.Drawing.Point(16, 8);
       this.label1.Name = "label1";
       this.label1.Size = new System.Drawing.Size(128, 16);
       this.label1.TabIndex = 0;
       this.label1.Text = "Regular Expression";
       //
       // RegexTextBox
       //
       this.RegexTextBox.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.RegexTextBox.Location = new System.Drawing.Point(16, 32);
       this.RegexTextBox.Multiline = true;
       this.RegexTextBox.Name = "RegexTextBox";
       this.RegexTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
       this.RegexTextBox.Size = new System.Drawing.Size(624, 40);
       this.RegexTextBox.TabIndex = 1;
       this.RegexTextBox.Text = "";
       //
       // OptionsGroup
       //
       this.OptionsGroup.Controls.Add(this.IgnorePatternWhiteSpaceChkBox);
       this.OptionsGroup.Controls.Add(this.SingleLineChkBox);
       this.OptionsGroup.Controls.Add(this.RightToLeftChkBox);
       this.OptionsGroup.Controls.Add(this.MultiLineChkBox);
       this.OptionsGroup.Controls.Add(this.IgnoreCaseChkBox);
       this.OptionsGroup.Controls.Add(this.ExplicitCaptureChkBox);
       this.OptionsGroup.Controls.Add(this.ECMAScriptChkBox);
       this.OptionsGroup.Location = new System.Drawing.Point(16, 80);
       this.OptionsGroup.Name = "OptionsGroup";
       this.OptionsGroup.Size = new System.Drawing.Size(456, 104);
       this.OptionsGroup.TabIndex = 2;
       this.OptionsGroup.TabStop = false;
       this.OptionsGroup.Text = "Regax Options";
       //
       // IgnorePatternWhiteSpaceChkBox
       //
       this.IgnorePatternWhiteSpaceChkBox.Location = new System.Drawing.Point(24, 80);
       this.IgnorePatternWhiteSpaceChkBox.Name = "IgnorePatternWhiteSpaceChkBox";
       this.IgnorePatternWhiteSpaceChkBox.Size = new System.Drawing.Size(184, 16);
       this.IgnorePatternWhiteSpaceChkBox.TabIndex = 6;
       this.IgnorePatternWhiteSpaceChkBox.Text = "IgnorePatternWhiteSpace";
       //
       // SingleLineChkBox
       //
       this.SingleLineChkBox.Location = new System.Drawing.Point(320, 56);
       this.SingleLineChkBox.Name = "SingleLineChkBox";
       this.SingleLineChkBox.Size = new System.Drawing.Size(96, 16);
       this.SingleLineChkBox.TabIndex = 5;
       this.SingleLineChkBox.Text = "SingleLine";
       //

共3页 首页 上一页 1 2 3 下一页 尾页 跳转到
相关内容
赞助商链接