C# split method returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.
Here is split example:
1 2 3 4 5 6 7 8 9 10 | string hobbies = "Swimming, Volleyball, Football, Reading Books"; string[] hList = hobbies.Split(','); //seperate the hobbies by comma foreach (string hobby in hList) { Console.WriteLine(hobby); } Console.ReadLine(); |
Output:
1 2 3 4 5 6 | Swimming Volleyball Football Reading Books |
C# Split example 2:ย More than one separator can be used to split the text
1 2 3 4 5 6 7 8 9 10 11 12 | string text = "www.chsarp-console-examples.com"; char[] seperator = { '.', '-' }; string[] list = text.Split(seperator); foreach (string item in list) { Console.WriteLine(item); } Console.ReadLine(); |
Output:
1 2 3 4 5 6 7 | www chsarp console examples com |
๐