| | |
Word break and line break in Rich Edit Control
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.
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
•
•
•
•
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.
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.
C++ Syntax (Toggle Plain Text)
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*
@ 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.
@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.
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.
cpp Syntax (Toggle Plain Text)
#include <string> #include <sstream> // Get the line from the Rich Edit Control . // Let's hard code it for this example. std::string line = "In that case this sentence has 27 words.\r\nThis is another line"; std::stringstream ss(line); std::string word; int count = 0; while ( ss >> word ){ std::cout << word << std::endl; count++ ; } std::cout << count << std::endl;
Last edited by WolfPack; Dec 17th, 2007 at 10:23 am. Reason: Included the header files
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.
C++ Syntax (Toggle Plain Text)
bool isLastCharBlank = true; int iWordCount = 0; char * szTemp = szInputString; while(*szTemp) { // Whitespase, tab, newline and carriage return if ((*szTemp == ' ') || (*szTemp == '\n') || (*szTemp == '\r')) { isLastCharBlank = true; } else if (isLastCharBlank) { iWordCount++; isLastCharBlank = false; } szTemp++; } 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
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
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
![]() |
Similar Threads
- Shortcuts (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Help regarding MSI Serial Key Validation
- Next Thread: I need help please
Views: 3659 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






