如何使用VB.NET在所选文本周围插入HTML标签? [英] How do I Insert HTML tags around selected text using VB.NET?

查看:61
本文介绍了如何使用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


这篇关于如何使用VB.NET在所选文本周围插入HTML标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆