Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

words counter c#


int wordCount = 0, index = 0;

// skip whitespace until first word
while (index < text.Length && char.IsWhiteSpace(text[index]))
    index++;

while (index < text.Length)
{
    // check if current char is part of a word
    while (index < text.Length && !char.IsWhiteSpace(text[index]))
        index++;

    wordCount++;

    // skip whitespace until next word
    while (index < text.Length && char.IsWhiteSpace(text[index]))
        index++;
}

Source by coders911.org #
 
PREVIOUS NEXT
Tagged: #words #counter
ADD COMMENT
Topic
Name
1+7 =