Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
count number of words in string
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public static class WordCount { public static int Count(string x) { int result = 0; //Trim whitespace from beginning and end of string x = x.Trim(); //Necessary because foreach will execute once with empty string returning 1 if (x == "") return 0; //Ensure there is only one space between each word in the passed string while (x.Contains(" ")) x = x.Replace(" ", " "); //Count the words foreach (string y in x.Split(' ')) result++; return result; } } }
run
|
edit
|
history
|
help
0
MidtermsGame_Rampage_12Geronimo
MegaWays
Lambdas
Task 2
Non-User input - Random Controlled - Guessing Game
DateTime and TimeSpan comparisons
числата от 1 до 20
List<int> into comma delimited string
sdfrgthyjukiujyht5r4der
problem_name