Click here to Skip to main content
15,891,473 members

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:

C#
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.
Tags: , , ,