In this article we will explain how to use Split method or what is Split method in c# with example.
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.
static void Main(string args)
string msg = "abhishek,divyanshu,aditya";
string strarr = msg.Split(',');
for (int i = 0; i < strarr.Length; i++)
Console.WriteLine("\nPress Enter Key to Exit..");
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.
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.