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
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,171
Location
Sydney, Australia
Programming Experience
10+
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)
 

rspercy65

New member
Joined
Jul 29, 2012
Messages
4
Programming Experience
10+
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:
Top Bottom