If I have a textBox that contains this information below wich meens 2 lines.
What I am trying to do is to search this textBox with a while loop for the word: "five"
and when found this word, I wonder if this word has any kind of substringindex where I can achieve these 3 values:

So for Ex: in this case the word "five" is located on:
Line: 1 and have startindex: 8 and endindex: 12
and
Line: 2 and have startindex: 5 and endindex: 9

one two five
four five six

I have put all lines in a textBox in an array like this:
I wonder how it is possible to search for the word "five" in the System:: String^ ReadLines:

"one five two"

if (textBox1->Text != "")
{
			
array<System::String^>^ ReadLines =  gcnew array<System::String^> ( textBox1->Lines->Length ); 
ReadLines = textBox1->Lines;

		  
 for(int count = 0; count < textBox1->Lines->Length; count++)
{
// search for word: "five" in the string "one five two"		
}



			}

I have managed up some code that I have put in my event handler for my textbox and this works in a way with one exception.

So what happens is when I write this line in the textBox now:

one two street

What happens when I press the last letter wich is "t", the word street selects, then I put the selected area to a blue color and then DeSelectAll.
When this code is executed, the cursor is put before the word street wich it should´t.

What I want is to still have the cursor where it should be as normal. (After the letter "t")
What also happens here is that blue is in memory and everything that is written after the word "street" will be blue. So I have to turn the color back to black.
Thanks.

This is the code selects the word and turn it blue as described above:
this->textBox1->Select((startPos - 4), endPos);
this->textBox1->SelectionColor = Color::Blue;
this->textBox1->DeselectAll();

string stringToFind1 = "stree";
	
if (textBox1->Text != "")
{
			
array<System::String^>^ ReadLines =  gcnew array<System::String^> ( textBox1->Lines->Length ); 

ReadLines = textBox1->Lines;

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

std::transform(Line1.begin(), Line1.end(), Line1.begin(), ::tolower);
std::string::size_type startPos = Line1.find(stringToFind1);
if ( startPos != std::string::npos )
{
         startPos += stringToFind1.length(); 
         std::string::size_type endPos = Line1.find("t", startPos); 
         if ( endPos != std::string::npos )
         {
            std::string Number = Line1.substr(startPos, endPos - startPos); 
            if ( Line1.find(stringToFind1) != std::string::npos )
            {
              
	this->textBox1->Select((startPos - 4), endPos);
	this->textBox1->SelectionColor = Color::Blue;
	this->textBox1->DeselectAll();

			  
            }
         }

				
}


}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.