RichTextBox.Find method fails to find known string.
-
In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.
private string GetHeadingInnerHtml() { int startPos = myRich.Find("", 0, RichTextBoxFinds.None); int endPos = 0; if (startPos >= 0) // Fails here! startPos value is 0xffffffff { endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None); myRich.SelectionStart = startPos; myRich.SelectionLength = ( endPos - startPos ); return myRich.SelectedText; } return string.Empty; }
:wtf: Any ideas why? Thanks.
-
In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.
private string GetHeadingInnerHtml() { int startPos = myRich.Find("", 0, RichTextBoxFinds.None); int endPos = 0; if (startPos >= 0) // Fails here! startPos value is 0xffffffff { endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None); myRich.SelectionStart = startPos; myRich.SelectionLength = ( endPos - startPos ); return myRich.SelectedText; } return string.Empty; }
:wtf: Any ideas why? Thanks.
What's your source text? The Find method which accepts string will not find text, if it is more than on one line.
Regards, Lev
-
In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.
private string GetHeadingInnerHtml() { int startPos = myRich.Find("", 0, RichTextBoxFinds.None); int endPos = 0; if (startPos >= 0) // Fails here! startPos value is 0xffffffff { endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None); myRich.SelectionStart = startPos; myRich.SelectionLength = ( endPos - startPos ); return myRich.SelectedText; } return string.Empty; }
:wtf: Any ideas why? Thanks.
If it returns -1, it ain't there. Are you sure there's no
Text
property in themyRich
object?"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.
private string GetHeadingInnerHtml() { int startPos = myRich.Find("", 0, RichTextBoxFinds.None); int endPos = 0; if (startPos >= 0) // Fails here! startPos value is 0xffffffff { endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None); myRich.SelectionStart = startPos; myRich.SelectionLength = ( endPos - startPos ); return myRich.SelectedText; } return string.Empty; }
:wtf: Any ideas why? Thanks.
This worked OK for me. I put the following text into a RTB and it found the details with no problem. <html> <head> <some tesxttlkajsdlfj asdf> </head> </html> If you debug your application, what does myRich.Text contain when you step into this method?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
-
If it returns -1, it ain't there. Are you sure there's no
Text
property in themyRich
object?"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001