How to use C# string Split

C# Split() handles splitting upon given string and character delimiters. It returns an array of String containing the substrings delimited by the given System.Char array.


If your String contains "dd-mm-yy", split on the "-" character to get an array of: "dd" "mm" "yy".

The String Split method ignores any element of separator whose value is null or the empty string ("").

Syntax :

string[] string.split(string[] separator)


separator - the given delimiter


An array of Strings delimited by one or more characters in separator

using System;
using System.Windows.Forms;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            string str = null;
            string[] strArr = null;
            int count = 0;
            str = "CSharp split test";
            char[] splitchar = { ' ' };
            strArr = str.Split(splitchar);
            for (count = 0; count < = strArr.Length - 1; count++)

When you execute this C# programme , you will get "CSharp" "split" "test" in separate messagebox.

 CSharp String - Related Contents

 CSharp String - Related Programs