Introduction:

In this article we will explain how to use Split method or what is Split method in c# with example.

Description:

In c# programming language, the string Split method is used to split a string into substrings based on the characters in an array. The split method will return a string array which contains a substrings that are delimited by the specified characters in an array.


C# String Split Method Example

Following is the below example of splitting the given string with comma (“,”) delimiter using Split() method in c# programming language.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SQLTutorialsPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            string msg = "abhishek,divyanshu,aditya";
            string[] strarr = msg.Split(',');
            for (int i = 0; i < strarr.Length; i++)
            {
                Console.WriteLine(strarr[i]);
            }
            Console.WriteLine("\nPress Enter Key to Exit..");
            Console.ReadLine();
        }
    }
}

 

As you see above example, we used a split() method to split the given string  ("abhishek,divyanshu,aditya") with comma (',') delimiter and returning a substrings as string array . Here we used a for loop to iterate through string array to display array elements.

 

When we execute above c# program, we will get the result like as shown below.

how to use String Split Method in C# with Example

 

In this article we have learned, how we can split a string with required delimiters using split() method in c# programming language.

 

 

I hope it will help to you after reading.

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like