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.

string stringToFind1 = "walke";
int positionen = 0;

positionen = textBox1->SelectionStart;
 if (textBox1->Text != "")

array<System::String^>^ ReadLines =  gcnew array<System::String^> ( textBox1->Lines->Length ); 
ReadLines = textBox1->Lines;

std::string Line1;
std::string Line2;	
 for(int count = 0; count < textBox1->Lines->Length; count++)
MarshalString(ReadLines[count], Line1);

Line2 = Line1.c_str();
std::transform(Line2.begin(), Line2.end(), Line2.begin(), ::tolower);
std::string::size_type startPos = Line2.find(stringToFind1);
      if ( startPos != std::string::npos )
         startPos += stringToFind1.length(); 
         std::string::size_type endPos = Line2.find("r", startPos); 
         if ( endPos != std::string::npos )

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.