Response to: Number of Words in a Sentence?(C# Console App)
Revision 1
Quote:
for (int i = indexfirstChar; i < indexLastChar + 1; i++)
{
if (st1[i].ToString() == " ")
counter++;
}
Change to:
bool newspace = false;
for (int i = indexfirstChar; i < indexLastChar + 1; i++)
{
if (st1[i].ToString() == " ")
{
if (! newspace )
{
counter++;
newspace = true;
}
}
else
{
if ( newspace )
{
newspace = false;
}
}
}
Posted 8-Oct-12 2:20am
by
CPallini.