如何使用VB.NET在所选文本周围插入HTML标签?

问题描述:

例如:过程"为突出显示的文本
附标签:"Procedure"

我正在尝试使用一个目前作为宠物项目工作的html编辑器来完成此任务.我所有的树形视图都加载了标签和它们的各个属性.如果选择了文本,则想用从树视图中选择的标签(上方)包围文本.现在,选定的文本为红色.它周围包裹着代码"标签.

感谢您对此帖子的任何回复.

rspercy65

ex: "Procedure" is highlighted text
ex w/tags: "Procedure"

I am trying to accomplish this in a html editor that I am currently working on as a pet project. I have all the my treeviews loaded with tags and thier individual properties. If I have selected text, I want to surround the text with a tag(above) that I select from the treeview. The selected text is now Red. This has the "code" tags wrapped around it.

Thanx, in advance, for any replies to this post.

rspercy65

我们不知道您是如何实现您的编辑器的,所以任何人说的都是纯粹的猜测.

但是,这不只是简单的字符串操作吗?插入文字< code>"和</code>"放入您的文本字符串中……
We have no idea how you''re implemented your editor, so anything anyone says it purely guess work.

But, wouldn''t this just be simple string manipulation? Inserting the text "<code>" and "</code>" into the string that is your text...


感谢Dave这么快的响应,我在发布后的一两分钟内解决了这个问题.这是我的解决方法...
Thanx Dave for such a quick response, I solved this a minute or two after I posted. Here is my solution...
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