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.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy C# Books
- Buy MCA Books
- Practice MCA MCQs
- Apply for C# Internship
- Buy Computer Science Books