Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Print dulicate chars in a string
remove special char c#
Numbers separated by space
Huffman Algorithm
an attempt at making a usable code thing
examen res
Proj2
Collection_ basic datastructure brushup
int array element change with xor
наименьшее общее кратное двух чисел a и b
Please log in to post a comment.