using System; using System.Text.RegularExpressions; class Program { static void Main() { string str = "Hello World"; string[] substrings = Regex.Split(str, @"\s+"); foreach (var substring in substrings) { Console.WriteLine(substring); } } }
using System; using System.Text.RegularExpressions; class Program { static void Main() { string str = "apple,banana,cherry"; string[] substrings = Regex.Split(str, ","); foreach (var substring in substrings) { Console.WriteLine(substring); } } }In this example, the input string "apple,banana,cherry" is split based on the comma character. This results in an array containing three substrings: "apple", "banana", and "cherry". Package library: System.Text.RegularExpressions.