I cant find what is wrong in this code

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

I cant find what is wrong in this code

 
0
  #1
Mar 19th, 2008
I use this code in a multilined textBox event handler. When writing:
"hellowalker" in the textBox:s first line, "walker" turns blue.
If you delete this and go down a line and write the same: "owalker" turns blue and down a line again "lowalker" turns blue.

What could be wrong with this code as I always want the word "walker" to turn blue.



  1. string stringToFind1 = "walke";
  2. int positionen = 0;
  3.  
  4. positionen = textBox1->SelectionStart;
  5.  
  6. if (textBox1->Text != "")
  7. {
  8.  
  9.  
  10.  
  11. array<System::String^>^ ReadLines = gcnew array<System::String^> ( textBox1->Lines->Length );
  12. ReadLines = textBox1->Lines;
  13.  
  14. std::string Line1;
  15. std::string Line2;
  16.  
  17. for(int count = 0; count < textBox1->Lines->Length; count++)
  18. {
  19.  
  20. MarshalString(ReadLines[count], Line1);
  21.  
  22.  
  23. Line2 = Line1.c_str();
  24. std::transform(Line2.begin(), Line2.end(), Line2.begin(), ::tolower);
  25. std::string::size_type startPos = Line2.find(stringToFind1);
  26. if ( startPos != std::string::npos )
  27. {
  28. startPos += stringToFind1.length();
  29. std::string::size_type endPos = Line2.find("r", startPos);
  30. if ( endPos != std::string::npos )
Last edited by Ancient Dragon; Mar 19th, 2008 at 9:56 pm. Reason: corrected code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: I cant find what is wrong in this code

 
0
  #2
Mar 20th, 2008
I'm guessing that you're looking for "walker" (or rather, "walke" going by your code) and highlighting the entire string regardless of whether the search string is a substring or the whole line.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Reply

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




Views: 400 | Replies: 1
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC