Click here to Skip to main content
15,898,035 members
Articles / Programming Languages / C#

Persistent String Parser

Rate me:
Please Sign up or sign in to vote.
4.33/5 (18 votes)
21 Dec 2008Public Domain4 min read 77.7K   382   38  
Parse a string with quoted elements, insert/add/delete elements, and is CLS compliant
namespace ParserTest
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.IDC_LISTBOX = new System.Windows.Forms.ListBox();
            this.IDC_EDIT_PARSE_STRING = new System.Windows.Forms.TextBox();
            this.IDC_CHECK_USE_QUOTES = new System.Windows.Forms.CheckBox();
            this.IDEC_EDIT_QUOTE_CHAR = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.IDC_EDIT_DELIMITER = new System.Windows.Forms.TextBox();
            this.IDC_BTN_PARSE = new System.Windows.Forms.Button();
            this.IDC_BTN_DONE = new System.Windows.Forms.Button();
            this.IDC_EDIT_ADD = new System.Windows.Forms.TextBox();
            this.IDC_BTN_ADDGO = new System.Windows.Forms.Button();
            this.IDC_BTN_INSERTGO = new System.Windows.Forms.Button();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.IDC_EDIT_INSERT = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.IDC_EDIT_POS = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.IDC_EDIT_DELINDEX = new System.Windows.Forms.TextBox();
            this.IDC_BTN_DELINDEX_GO = new System.Windows.Forms.Button();
            this.label8 = new System.Windows.Forms.Label();
            this.IDC_EDIT_DELSTRING = new System.Windows.Forms.TextBox();
            this.IDC_CHECK_EXACTMATCH = new System.Windows.Forms.CheckBox();
            this.IDC_BTN_DELSTRING_GO = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.IDC_RADIO_DELLAST = new System.Windows.Forms.RadioButton();
            this.IDC_RADIO_DELFIRST = new System.Windows.Forms.RadioButton();
            this.label10 = new System.Windows.Forms.Label();
            this.IDC_RADIO_DELALL = new System.Windows.Forms.RadioButton();
            this.label9 = new System.Windows.Forms.Label();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // IDC_LISTBOX
            // 
            this.IDC_LISTBOX.FormattingEnabled = true;
            this.IDC_LISTBOX.Location = new System.Drawing.Point(10, 362);
            this.IDC_LISTBOX.Name = "IDC_LISTBOX";
            this.IDC_LISTBOX.Size = new System.Drawing.Size(382, 160);
            this.IDC_LISTBOX.TabIndex = 25;
            // 
            // IDC_EDIT_PARSE_STRING
            // 
            this.IDC_EDIT_PARSE_STRING.Location = new System.Drawing.Point(20, 39);
            this.IDC_EDIT_PARSE_STRING.Name = "IDC_EDIT_PARSE_STRING";
            this.IDC_EDIT_PARSE_STRING.Size = new System.Drawing.Size(362, 20);
            this.IDC_EDIT_PARSE_STRING.TabIndex = 1;
            // 
            // IDC_CHECK_USE_QUOTES
            // 
            this.IDC_CHECK_USE_QUOTES.AutoSize = true;
            this.IDC_CHECK_USE_QUOTES.Location = new System.Drawing.Point(20, 94);
            this.IDC_CHECK_USE_QUOTES.Name = "IDC_CHECK_USE_QUOTES";
            this.IDC_CHECK_USE_QUOTES.Size = new System.Drawing.Size(142, 17);
            this.IDC_CHECK_USE_QUOTES.TabIndex = 4;
            this.IDC_CHECK_USE_QUOTES.Text = "Use this quote character";
            this.IDC_CHECK_USE_QUOTES.UseVisualStyleBackColor = true;
            // 
            // IDEC_EDIT_QUOTE_CHAR
            // 
            this.IDEC_EDIT_QUOTE_CHAR.Location = new System.Drawing.Point(162, 92);
            this.IDEC_EDIT_QUOTE_CHAR.MaxLength = 1;
            this.IDEC_EDIT_QUOTE_CHAR.Name = "IDEC_EDIT_QUOTE_CHAR";
            this.IDEC_EDIT_QUOTE_CHAR.Size = new System.Drawing.Size(33, 20);
            this.IDEC_EDIT_QUOTE_CHAR.TabIndex = 5;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(17, 23);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(78, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "String to parse:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(17, 70);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(244, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "Delimiter (can be a string up to 10 characters long)";
            // 
            // IDC_EDIT_DELIMITER
            // 
            this.IDC_EDIT_DELIMITER.Location = new System.Drawing.Point(262, 68);
            this.IDC_EDIT_DELIMITER.MaxLength = 10;
            this.IDC_EDIT_DELIMITER.Name = "IDC_EDIT_DELIMITER";
            this.IDC_EDIT_DELIMITER.Size = new System.Drawing.Size(119, 20);
            this.IDC_EDIT_DELIMITER.TabIndex = 3;
            // 
            // IDC_BTN_PARSE
            // 
            this.IDC_BTN_PARSE.Location = new System.Drawing.Point(163, 121);
            this.IDC_BTN_PARSE.Name = "IDC_BTN_PARSE";
            this.IDC_BTN_PARSE.Size = new System.Drawing.Size(75, 23);
            this.IDC_BTN_PARSE.TabIndex = 6;
            this.IDC_BTN_PARSE.Text = "Parse";
            this.IDC_BTN_PARSE.UseVisualStyleBackColor = true;
            this.IDC_BTN_PARSE.Click += new System.EventHandler(this.IDC_BTN_PARSE_Click);
            // 
            // IDC_BTN_DONE
            // 
            this.IDC_BTN_DONE.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.IDC_BTN_DONE.Location = new System.Drawing.Point(164, 530);
            this.IDC_BTN_DONE.Name = "IDC_BTN_DONE";
            this.IDC_BTN_DONE.Size = new System.Drawing.Size(75, 23);
            this.IDC_BTN_DONE.TabIndex = 26;
            this.IDC_BTN_DONE.Text = "Done";
            this.IDC_BTN_DONE.UseVisualStyleBackColor = true;
            this.IDC_BTN_DONE.Click += new System.EventHandler(this.IDC_BTN_DONE_Click);
            // 
            // IDC_EDIT_ADD
            // 
            this.IDC_EDIT_ADD.Location = new System.Drawing.Point(95, 178);
            this.IDC_EDIT_ADD.Name = "IDC_EDIT_ADD";
            this.IDC_EDIT_ADD.Size = new System.Drawing.Size(112, 20);
            this.IDC_EDIT_ADD.TabIndex = 9;
            // 
            // IDC_BTN_ADDGO
            // 
            this.IDC_BTN_ADDGO.Location = new System.Drawing.Point(320, 177);
            this.IDC_BTN_ADDGO.Name = "IDC_BTN_ADDGO";
            this.IDC_BTN_ADDGO.Size = new System.Drawing.Size(32, 23);
            this.IDC_BTN_ADDGO.TabIndex = 10;
            this.IDC_BTN_ADDGO.Text = "Go";
            this.IDC_BTN_ADDGO.UseVisualStyleBackColor = true;
            this.IDC_BTN_ADDGO.Click += new System.EventHandler(this.IDC_BTN_ADDGO_Click);
            // 
            // IDC_BTN_INSERTGO
            // 
            this.IDC_BTN_INSERTGO.Location = new System.Drawing.Point(319, 213);
            this.IDC_BTN_INSERTGO.Name = "IDC_BTN_INSERTGO";
            this.IDC_BTN_INSERTGO.Size = new System.Drawing.Size(33, 23);
            this.IDC_BTN_INSERTGO.TabIndex = 15;
            this.IDC_BTN_INSERTGO.Text = "Go";
            this.IDC_BTN_INSERTGO.UseVisualStyleBackColor = true;
            this.IDC_BTN_INSERTGO.Click += new System.EventHandler(this.IDC_BTN_INSERTGO_Click);
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(316, 167);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(0, 13);
            this.label3.TabIndex = 10;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(20, 182);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(67, 13);
            this.label4.TabIndex = 8;
            this.label4.Text = "Add this field";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(20, 218);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(74, 13);
            this.label5.TabIndex = 11;
            this.label5.Text = "Insert this field";
            // 
            // IDC_EDIT_INSERT
            // 
            this.IDC_EDIT_INSERT.Location = new System.Drawing.Point(95, 214);
            this.IDC_EDIT_INSERT.Name = "IDC_EDIT_INSERT";
            this.IDC_EDIT_INSERT.Size = new System.Drawing.Size(112, 20);
            this.IDC_EDIT_INSERT.TabIndex = 12;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(214, 218);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(65, 13);
            this.label6.TabIndex = 13;
            this.label6.Text = "before index";
            // 
            // IDC_EDIT_POS
            // 
            this.IDC_EDIT_POS.Location = new System.Drawing.Point(280, 214);
            this.IDC_EDIT_POS.MaxLength = 3;
            this.IDC_EDIT_POS.Name = "IDC_EDIT_POS";
            this.IDC_EDIT_POS.Size = new System.Drawing.Size(33, 20);
            this.IDC_EDIT_POS.TabIndex = 14;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(20, 254);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(66, 13);
            this.label7.TabIndex = 16;
            this.label7.Text = "Delete index";
            // 
            // IDC_EDIT_DELINDEX
            // 
            this.IDC_EDIT_DELINDEX.Location = new System.Drawing.Point(95, 250);
            this.IDC_EDIT_DELINDEX.MaxLength = 3;
            this.IDC_EDIT_DELINDEX.Name = "IDC_EDIT_DELINDEX";
            this.IDC_EDIT_DELINDEX.Size = new System.Drawing.Size(43, 20);
            this.IDC_EDIT_DELINDEX.TabIndex = 17;
            // 
            // IDC_BTN_DELINDEX_GO
            // 
            this.IDC_BTN_DELINDEX_GO.Location = new System.Drawing.Point(319, 249);
            this.IDC_BTN_DELINDEX_GO.Name = "IDC_BTN_DELINDEX_GO";
            this.IDC_BTN_DELINDEX_GO.Size = new System.Drawing.Size(33, 23);
            this.IDC_BTN_DELINDEX_GO.TabIndex = 18;
            this.IDC_BTN_DELINDEX_GO.Text = "Go";
            this.IDC_BTN_DELINDEX_GO.UseVisualStyleBackColor = true;
            this.IDC_BTN_DELINDEX_GO.Click += new System.EventHandler(this.IDC_BTN_DELINDEX_GO_Click);
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(20, 287);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(66, 13);
            this.label8.TabIndex = 19;
            this.label8.Text = "Delete string";
            // 
            // IDC_EDIT_DELSTRING
            // 
            this.IDC_EDIT_DELSTRING.Location = new System.Drawing.Point(95, 283);
            this.IDC_EDIT_DELSTRING.Name = "IDC_EDIT_DELSTRING";
            this.IDC_EDIT_DELSTRING.Size = new System.Drawing.Size(112, 20);
            this.IDC_EDIT_DELSTRING.TabIndex = 20;
            // 
            // IDC_CHECK_EXACTMATCH
            // 
            this.IDC_CHECK_EXACTMATCH.AutoSize = true;
            this.IDC_CHECK_EXACTMATCH.Location = new System.Drawing.Point(218, 285);
            this.IDC_CHECK_EXACTMATCH.Name = "IDC_CHECK_EXACTMATCH";
            this.IDC_CHECK_EXACTMATCH.Size = new System.Drawing.Size(85, 17);
            this.IDC_CHECK_EXACTMATCH.TabIndex = 21;
            this.IDC_CHECK_EXACTMATCH.Text = "Exact match";
            this.IDC_CHECK_EXACTMATCH.UseVisualStyleBackColor = true;
            // 
            // IDC_BTN_DELSTRING_GO
            // 
            this.IDC_BTN_DELSTRING_GO.Location = new System.Drawing.Point(319, 293);
            this.IDC_BTN_DELSTRING_GO.Name = "IDC_BTN_DELSTRING_GO";
            this.IDC_BTN_DELSTRING_GO.Size = new System.Drawing.Size(33, 23);
            this.IDC_BTN_DELSTRING_GO.TabIndex = 22;
            this.IDC_BTN_DELSTRING_GO.Text = "Go";
            this.IDC_BTN_DELSTRING_GO.UseVisualStyleBackColor = true;
            this.IDC_BTN_DELSTRING_GO.Click += new System.EventHandler(this.IDC_BTN_DELSTRING_GO_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Location = new System.Drawing.Point(9, 2);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(383, 153);
            this.groupBox1.TabIndex = 7;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Do This First";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.IDC_RADIO_DELLAST);
            this.groupBox2.Controls.Add(this.IDC_RADIO_DELFIRST);
            this.groupBox2.Controls.Add(this.label10);
            this.groupBox2.Controls.Add(this.IDC_RADIO_DELALL);
            this.groupBox2.Location = new System.Drawing.Point(9, 159);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(383, 180);
            this.groupBox2.TabIndex = 23;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Exercise Other Functions";
            // 
            // IDC_RADIO_DELLAST
            // 
            this.IDC_RADIO_DELLAST.AutoSize = true;
            this.IDC_RADIO_DELLAST.Location = new System.Drawing.Point(218, 151);
            this.IDC_RADIO_DELLAST.Name = "IDC_RADIO_DELLAST";
            this.IDC_RADIO_DELLAST.Size = new System.Drawing.Size(45, 17);
            this.IDC_RADIO_DELLAST.TabIndex = 3;
            this.IDC_RADIO_DELLAST.TabStop = true;
            this.IDC_RADIO_DELLAST.Text = "Last";
            this.IDC_RADIO_DELLAST.UseVisualStyleBackColor = true;
            // 
            // IDC_RADIO_DELFIRST
            // 
            this.IDC_RADIO_DELFIRST.AutoSize = true;
            this.IDC_RADIO_DELFIRST.Location = new System.Drawing.Point(169, 151);
            this.IDC_RADIO_DELFIRST.Name = "IDC_RADIO_DELFIRST";
            this.IDC_RADIO_DELFIRST.Size = new System.Drawing.Size(44, 17);
            this.IDC_RADIO_DELFIRST.TabIndex = 2;
            this.IDC_RADIO_DELFIRST.TabStop = true;
            this.IDC_RADIO_DELFIRST.Text = "First";
            this.IDC_RADIO_DELFIRST.UseVisualStyleBackColor = true;
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(82, 152);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(38, 13);
            this.label10.TabIndex = 0;
            this.label10.Text = "Delete";
            // 
            // IDC_RADIO_DELALL
            // 
            this.IDC_RADIO_DELALL.AutoSize = true;
            this.IDC_RADIO_DELALL.Location = new System.Drawing.Point(127, 151);
            this.IDC_RADIO_DELALL.Name = "IDC_RADIO_DELALL";
            this.IDC_RADIO_DELALL.Size = new System.Drawing.Size(36, 17);
            this.IDC_RADIO_DELALL.TabIndex = 1;
            this.IDC_RADIO_DELALL.TabStop = true;
            this.IDC_RADIO_DELALL.Text = "All";
            this.IDC_RADIO_DELALL.UseVisualStyleBackColor = true;
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(9, 347);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(42, 13);
            this.label9.TabIndex = 24;
            this.label9.Text = "Results";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(402, 562);
            this.Controls.Add(this.label9);
            this.Controls.Add(this.IDC_BTN_DELSTRING_GO);
            this.Controls.Add(this.IDC_CHECK_EXACTMATCH);
            this.Controls.Add(this.IDC_EDIT_DELSTRING);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.IDC_BTN_DELINDEX_GO);
            this.Controls.Add(this.IDC_EDIT_DELINDEX);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.IDC_EDIT_POS);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.IDC_EDIT_INSERT);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.IDC_BTN_INSERTGO);
            this.Controls.Add(this.IDC_BTN_ADDGO);
            this.Controls.Add(this.IDC_EDIT_ADD);
            this.Controls.Add(this.IDC_BTN_DONE);
            this.Controls.Add(this.IDC_BTN_PARSE);
            this.Controls.Add(this.IDC_EDIT_DELIMITER);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.IDEC_EDIT_QUOTE_CHAR);
            this.Controls.Add(this.IDC_CHECK_USE_QUOTES);
            this.Controls.Add(this.IDC_EDIT_PARSE_STRING);
            this.Controls.Add(this.IDC_LISTBOX);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.groupBox2);
            this.Name = "Form1";
            this.Text = "CQStringParser Test";
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ListBox IDC_LISTBOX;
        private System.Windows.Forms.TextBox IDC_EDIT_PARSE_STRING;
        private System.Windows.Forms.CheckBox IDC_CHECK_USE_QUOTES;
        private System.Windows.Forms.TextBox IDEC_EDIT_QUOTE_CHAR;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox IDC_EDIT_DELIMITER;
        private System.Windows.Forms.Button IDC_BTN_PARSE;
        private System.Windows.Forms.Button IDC_BTN_DONE;
        private System.Windows.Forms.TextBox IDC_EDIT_ADD;
        private System.Windows.Forms.Button IDC_BTN_ADDGO;
        private System.Windows.Forms.Button IDC_BTN_INSERTGO;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.TextBox IDC_EDIT_INSERT;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.TextBox IDC_EDIT_POS;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.TextBox IDC_EDIT_DELINDEX;
        private System.Windows.Forms.Button IDC_BTN_DELINDEX_GO;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.TextBox IDC_EDIT_DELSTRING;
        private System.Windows.Forms.CheckBox IDC_CHECK_EXACTMATCH;
        private System.Windows.Forms.Button IDC_BTN_DELSTRING_GO;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.RadioButton IDC_RADIO_DELALL;
        private System.Windows.Forms.RadioButton IDC_RADIO_DELLAST;
        private System.Windows.Forms.RadioButton IDC_RADIO_DELFIRST;
        private System.Windows.Forms.Label label10;
        private System.Windows.Forms.Label label9;
    }
}

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 A Public Domain dedication


Written By
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions