|
-
Aug 18th, 2012, 08:09 AM
#1
Thread Starter
Lively Member
[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
-
Aug 18th, 2012, 08:16 AM
#2
Re: Checking for Selected Text and Replacing Selected Text
Code:
RichTextBox1.SelectedText = pathC
-
Aug 18th, 2012, 08:26 AM
#3
Thread Starter
Lively Member
Re: Checking for Selected Text and Replacing Selected Text
 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
-
Aug 18th, 2012, 08:50 AM
#4
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
-
Aug 18th, 2012, 12:36 PM
#5
Thread Starter
Lively Member
Re: [RESOLVED] Checking for Selected Text and Replacing Selected Text
Is always good to know thanks mate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|