[RESOLVED] Checking for Selected Text and Replacing Selected Text
Hi guys ,
I have a RichTextBox and i'm trying to be able to add links to selected text,
So i've been messing around with the SelectedText but It's not working the way I thought.
Code:
Dim Selection As String = ""
Dim link As String = ""
Dim pathC As String = ""
If RichTextBox1.SelectedText <> "" Then
Selection = RichTextBox1.SelectedText
If MsgBox("Would you Like to Add an external link?", MsgBoxStyle.YesNo, "Link type") = MsgBoxResult.Yes Then
link = InputBox("Type hyperlink", "Type hyperlink", "http://")
pathC = "<a href=""" & link & """>" & Selection & "</a>"
RichTextBox1.SelectedText.Replace(RichTextBox1.SelectedText, pathC)
Else
...
End If
End If
Thanks in advance,
Mike
Re: Checking for Selected Text and Replacing Selected Text
Code:
RichTextBox1.SelectedText = pathC
Re: Checking for Selected Text and Replacing Selected Text
Quote:
Originally Posted by
Inferrd
Code:
RichTextBox1.SelectedText = pathC
lol
I was going the other way. it always amazes me how everything becomes so simple.
Thanks a lot
Re: [RESOLVED] Checking for Selected Text and Replacing Selected Text
np.
Just a quick note: the String Replace method "Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string" (from the MSDN docs) and it's that "returns a new string" bit that tends to trip people up on occasion (me included). So your original approach should work as:
Code:
RichTextBox1.SelectedText = RichTextBox1.SelectedText.Replace(RichTextBox1.SelectedText, pathC)
Bit of a mouthful, though. :P
Re: [RESOLVED] Checking for Selected Text and Replacing Selected Text
Is always good to know thanks mate :D