This is a C# Program to implement string splitter.
This C# Program Implements String Splitter.
Here it Returns a string array that contains the substrings in this string that are delimited by elements of a specified string array.
Here is source code of the C# Program to Implement String Splitter. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Implement String Splitter */ using System; using System.Text.RegularExpressions; class Program { static void Main() { string sentence = "School had 40 Rooms, 500 Boys, 500 Girls and 250 Teachers"; string[] digits = Regex.Split(sentence, @"\D+"); foreach (string value in digits) { int number; if (int.TryParse(value, out number)) { Console.Write(value); } Console.ReadLine(); } } }
This C# program is used to implement string splitter. We have already defined a sentence using ‘sentence’ variable. The Regex.Split() function is used to split an input string into an array of substrings at the position, defined by a regular expression pattern specified in the Regex constructor. Return a string array that contains the substrings in this string that are delimited by elements of a specified string array.
40 500 500 250
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Practice Computer Science MCQs
- Check C# Books
- Practice MCA MCQs
- Check MCA Books
- Apply for C# Internship