String Split - SQL Programmers

String Split

01/10/2012

There are different ways split the string based on the delimiter. Here is one of the examples in C# to split the string. Place two textboxes in the form. Rename the first textbox to txtString and second textbox to txtDelimited.

String spilt

private void btnsplit_Click(object sender, EventArgs e)
        {

            string str = txtString.Text;
            string strSplit = txtDelimited.Text;
            Regex reg = new Regex(strSplit);
            string[] myString = reg.Split(str);
            string Result=string.Empty;
            foreach (object res in myString)
            {
                Result = Result + res.ToString() + "\n";
            }
            MessageBox.Show(Result);
        }

The above code will split the delimited from the given text.