Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Split function in C#

Here is a small post about using split function in c#. We are going to split a String by using delimiters. A delimiter will tell when to split the string. So here is a fragment of code to perform splitting.

String answer = "This$is|a|string";

char[] delimitator1 = new char[] { '$' };

char[] delimitator2 = new char[] { '|' };

string[] words = answer.Split(delimitator1);

Console.WriteLine("First word : " + words[0]);

//Note that now we split the second part of the string

String allRest = words[1];

string[] rest1 = allRest.Split(delimitator2);

Console.WriteLine("Second word : " + rest1[0]);

Console.WriteLine("Third word : " + rest1[1]);

Console.WriteLine("Fourth word : " + rest1[2]);


Output:


This post first appeared on Practical C# Codes, please read the originial post: here

Share the post

Split function in C#

×

Subscribe to Practical C# Codes

Get updates delivered right to your inbox!

Thank you for your subscription

×