C# Code Interview: Count Words in String on CoderPad

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • In todays video we are going to go over a common code interview question that can come up which is simply to count the words in a string. We will be using C# as our language and CoderPad as our tool.

КОМЕНТАРІ • 2

  • @milanekrkane
    @milanekrkane 8 місяців тому

    public static string StringCount(string s)
    {
    var sl = s.Split().ToList();
    return sl.Count().ToString();
    }

  • @KathleenWestUSA
    @KathleenWestUSA 10 місяців тому +1

    string myString = "Word1, Word2! Word3. Word4";
    char[] delimiters = new char[] {' ', '
    ', '
    '};
    int numberWords = myString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length;
    Console.WriteLine($"Number of Words {numberWords}");