• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Knowing how many words are in each string sentence?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been working all day on trying to get a paragraph string, and finding out how many sentences it has, how many words it has in each sentence, and which words are small words (below 4 letters.)

I'm totally not getting it.



Any hints? I'm totally stuck at a dead end and i've been sitting here trying to figure this out for around.. 5 hours so far non stop with searching and so far. I believe it needs loops to determine most of these but i just don't know where to start.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Any hints? I'm totally stuck at a dead end and i've been sitting here trying to figure this out for around.. 5 hours so far non stop with searching and so far. I believe it needs loops to determine most of these but i just don't know where to start.




What else have you tried during those 5 hours? Maybe some of the ideas that you had, or code that you attempted, and failed, where actually good ideas, and we can give you a hint in the right direction.

After 5 hours, you must have tons of questions to ask.

Henry
 
vahid mirjamal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hehe your so right, I'm starting to go back and see my old code and it's not all bad. Like I got here so far:



But for for some reason it counts the extra spaces as an extra word, how can i get it to stop counting the extra space? If i figure that out I should be closer to figuring this out. I got it to exclude double spaces, etc from my first regex:


But it doesn't seem to be working in the counting words one..
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But for for some reason it counts the extra spaces as an extra word, how can i get it to stop counting the extra space? If i figure that out I should be closer to figuring this out. I got it to exclude double spaces, etc from my first regex:

But it doesn't seem to be working in the counting words one..



The extra space is probably in the beginning of the sentence -- as people generally put a space after the period from the previous sentence. You may want to consider trimming the sentence before splitting it.

Another option is to loop through the word list (after the sentence is split) and check to make sure that every word has at least 1 character. If it is splitting an extra word due to an extra space, the extra word should be a zero-length string.

Henry
 
vahid mirjamal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Like that?

Because it's not exactly working :|
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Like that?



Actually, no.... I suggested that you trim the sentence. Not the paragraph. (And it was only speculation, as you never showed us the actual symtoms).

I also suggested that you count the words -- by checking if the length is greater than zero -- which you didn't even attempt.

Because it's not exactly working :|



Statements like "it's not exactly working" is completely useless here. You need to describe what you did. what you expected, what you got, and.... You need to attempt to debug the code to try to isolate where the problem is. Or at least speculate.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic