Saturday, 2 December 2017

C# Program to Implement String Splitter


Code:

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();
        }
    }
}


Output:

40
500
500
250


More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...