How to count the number of spaces in a string with C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "c # . n e t";
        
        int spaceCount = s.Split(" ").Length - 1;

        Console.WriteLine(spaceCount);
    }
}




/*
run:
  
5

*/

 



answered Sep 28, 2021 by avibootz

Related questions

...