Word break and line break in Rich Edit Control

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Word break and line break in Rich Edit Control

 
0
  #1
Dec 17th, 2007
Hi all,

I want to find the number of words in a rich edit control. There is no direct class member to do this. So I think if I can count the number of word break and line brake then it is easy. But it is also not easy. On the MSDN also it is not well documented. Can you guys give me a clue.

Thanks.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Word break and line break in Rich Edit Control

 
0
  #2
Dec 17th, 2007
Originally Posted by eranga262154 View Post
Hi all,

I want to find the number of words in a rich edit control. There is no direct class member to do this. So I think if I can count the number of word break and line brake then it is easy. But it is also not easy. On the MSDN also it is not well documented. Can you guys give me a clue.

Thanks.
If your RichEdit control is on a dialog box call GetDlgItemText and then count the number of spaces in the lpString.
You can also use EM_GETTEXTRANGE message if you know the handle of the control to retrive the text and then count number of white space.

Number of Words = Number of space + 1
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Word break and line break in Rich Edit Control

 
0
  #3
Dec 17th, 2007
Originally Posted by dubeyprateek View Post

Number of Words = Number of space + 1

  1. In that case this sentence has 27 words.
Last edited by iamthwee; Dec 17th, 2007 at 9:51 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Word break and line break in Rich Edit Control

 
0
  #4
Dec 17th, 2007
Originally Posted by iamthwee View Post
  1. In that case this sentence has 27 words.
@ iamthwee Thanks!

@eranga262154 Once you get the string, counting the number of words should not be a big problem.

"Number of Words = Number of space + 1" is focusing simplest case. However, be careful you may have audience and users like iamthwee (no offence), who may spoil your algorithm.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Word break and line break in Rich Edit Control

 
2
  #5
Dec 17th, 2007
Something like this will be easy. There are more compilicated methods if you want to break Japanese or Chinese words. Also you can use a callback function to count the words on the fly, but I think this is the most simple way.

  1.  
  2. #include <string>
  3. #include <sstream>
  4.  
  5. // Get the line from the Rich Edit Control .
  6. // Let's hard code it for this example.
  7. std::string line = "In that case this sentence has 27 words.\r\nThis is another line";
  8. std::stringstream ss(line);
  9. std::string word;
  10. int count = 0;
  11.  
  12. while ( ss >> word ){
  13. std::cout << word << std::endl;
  14. count++ ;
  15. }
  16. std::cout << count << std::endl;
Last edited by WolfPack; Dec 17th, 2007 at 10:23 am. Reason: Included the header files
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Re: Word break and line break in Rich Edit Control

 
0
  #6
Dec 17th, 2007
Originally Posted by dubeyprateek View Post
Number of Words = Number of space + 1
Yes that's what I'm going to do. Find the number of spaces, tabs, carriage returns of the string. I can get the string from the rich edit control. How about the following attempt.

  1. bool isLastCharBlank = true;
  2. int iWordCount = 0;
  3.  
  4. char * szTemp = szInputString;
  5.  
  6. while(*szTemp)
  7. {
  8. // Whitespase, tab, newline and carriage return
  9. if ((*szTemp == ' ') || (*szTemp == '\n') || (*szTemp == '\r'))
  10. {
  11. isLastCharBlank = true;
  12. }
  13.  
  14. else if (isLastCharBlank)
  15. {
  16. iWordCount++;
  17. isLastCharBlank = false;
  18. }
  19. szTemp++;
  20. }
  21. printf("Number of words %d",iWordCount);
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Re: Word break and line break in Rich Edit Control

 
0
  #7
Dec 17th, 2007
Originally Posted by iamthwee View Post
  1. In that case this sentence has 27 words.
That is one of the big problem I've got. Multiple such instances(like spaces and tab, two spaces, and such..). So please look at my code, how I try to avoid it.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Word break and line break in Rich Edit Control

 
0
  #8
Dec 18th, 2007
Did you see my code snippet? Why can't you use that?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Re: Word break and line break in Rich Edit Control

 
0
  #9
Dec 18th, 2007
Originally Posted by WolfPack View Post
  1.  
  2.  
  3. std::stringstream ss(line);
Yes, I check your code as well. But is this valid. Got an compile error.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Word break and line break in Rich Edit Control

 
0
  #10
Dec 18th, 2007
have you included the header file?

#include <sstream>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC