Question Insert HTML tags around highlighted text?

rspercy65

New member
Joined
Jul 29, 2012
Messages
4
Programming Experience
10+
How would I place HTML tags around selected text using VB.NET?
If this is my selected text "Procedure", How do I go about adding tags to this string?
ex: <code>Procedure</code>

Thanx, in advance, for any replies to this post.
rspercy65
 
I'm going to assume that you mean selected in a TextBox and be rather annoyed if you don't.
myTextBox.SelectedText = String.Format("<code>{0}</code>", myTextBox.SelectedText)
 
Thanx for the quick reply... I solved it by myself a few minutes after I posted.
Here is the code...
Private
Sub tvHTML5_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvHTML5.AfterSelect


Dim selectedText As String = fctbHTML.SelectedText


If selectedText <> vbNullString Then


Dim parts() As String


parts = e.Node.Text.Split(">")


If parts(0).StartsWith("<") Then


fctbHTML.InsertText(parts(0) & ">" & selectedText & parts(1) & ">")


Exit Sub


End If


'Else we do nothing


End If



fctbHTML.InsertText(e.Node.Text)


End Sub
 
Last edited:
Back
Top