当前位置: 源码素材网 » VB教程 » 详情页

VB 将RTF控件字符串内容转换为Html字符串

  •   时间:2019-06-03
  • 概述:RTF 字符串转换

VB 将RTF控件内容转换为Html字符串,这个实际上是字符串的转换,需要替换和添加一些HTML专有的标签,最后对sDeal字符串进行RTF到HTML的字体转换,这里仅给出了关键的转换函数:

'*Rtf2Html
'*功能:将RTF控件内容转换为Html字符串
'*说明:
'*传入参数:
'*    rTxt  类型:RichTextBox
'*返回参数:
'*      HTML字符串
'*作者:progame
Public Function Rtf2Html(ctrl As RichTextBox) As String
Dim byt()       As Byte
Dim sFileName   As String
    sFileName = TempFileName
    HighLightCtrl ctrl, sFileName, False
    '*读入文件
    Open sFileName For Binary As #1
        ReDim byt(1 To FileLen(sFileName))
        Get #1, , byt
    Close #1
    If Dir(sFileName) <> "" Then
        Kill sFileName
    End If
    Rtf2Html = StrConv(byt, vbUnicode)
    '*将特殊字符恢复
    Rtf2Html = Replace(Rtf2Html, "\\", "\")
    Rtf2Html = Replace(Rtf2Html, "\{", "{")
    Rtf2Html = Replace(Rtf2Html, "\}", "}")
    '*先删除RTF文件头
    Rtf2Html = Replace(Rtf2Html, HEAD_FIRST & m_sColorRtf & HEAD_LAST, "", , 1)
    '*转换换行符号
    Rtf2Html = Replace(Rtf2Html, "\par ", "")
    '*将特殊字符处理
    Rtf2Html = Replace(Rtf2Html, "&", "&amp;")
    Rtf2Html = Replace(Rtf2Html, "<", "&lt;")
    Rtf2Html = Replace(Rtf2Html, ">", "&gt;")
    '*转换注释字体符号
    FontRtf2Html Rtf2Html, m_objQuotFont
    FontRtf2Html Rtf2Html, m_objCommFont
    Dim i       As Integer
    For i = 1 To m_iKwdCount
        FontRtf2Html Rtf2Html, m_objKwdFont(i)
    Next i
    '*去除最后一个"}"
    Rtf2Html = Left(Rtf2Html, Len(Rtf2Html) - 4)
    '*加上HTML头尾
    Rtf2Html = HEAD_HTML & Rtf2Html & TAIL_HTML
End Function
Private Sub FontRtf2Html(ByRef sDeal As String, ByRef objFont As CFont)
'*对sDeal字符串进行RTF到HTML的字体转换
    sDeal = Replace(sDeal, objFont.getRtfHead(m_objColorManager), objFont.getHtmlHead(m_objColorManager))
    sDeal = Replace(sDeal, objFont.getRtfTail, objFont.getHtmlTail)
End Sub

    相关声明:

      若“VB 将RTF控件字符串内容转换为Html字符串”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。