文章標題、內容、摘要的處理函數

來源:互聯網
上載者:User

Imports System.Data
Imports System.Text.RegularExpressions
Imports System.Data.OleDb
Public Class ShowArticle
    Inherits System.Web.UI.Page

#Region " Web Form設計器產生的程式碼 "

    '該調用是 Web Form設計器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents LblTitle As System.Web.UI.WebControls.Label
    Protected WithEvents LblContent As System.Web.UI.WebControls.Label

    '注意: 以下預留位置聲明是 Web Form設計器所必需的。
    '不要刪除或移動它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法調用是 Web Form設計器所必需的
        '不要使用代碼編輯器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此處放置初始化頁的使用者代碼
        Dim StrArticleId As String
        StrArticleId = Request("ArticleId")
        Dim myArticle As New AccessDb
        Dim myReader As OleDbDataReader
        Dim myStrTitle As String
        myReader = myArticle.ExecuteSqlStrDetails("select * from portal_Articles where articleid=" + StrArticleId + ";")
        If myReader.Read Then
            myStrTitle = myReader("title")
            If strlen(myStrTitle) > 20 Then
                myStrTitle = gotTopic(myStrTitle, 20)
            End If
            LblTitle.Text = myStrTitle
            LblContent.Text = HTMLEncode(myReader("Content"))
        End If
    End Sub
    Function HTMLEncode(ByVal reString As String) '轉換HTML代碼
        Dim Str As String = reString
        If Str.Length > 0 Then
            Str = Replace(Str, ">", "&gt;")
            Str = Replace(Str, "<", "&lt;")
            Str = Replace(Str, Chr(9), "&nbsp;")
            Str = Replace(Str, Chr(39), "'")
            Str = Replace(Str, Chr(34), "&quot;")
            Str = Replace(Str, Chr(13), "")
            Str = Replace(Str, Chr(10), "<br/>")
            HTMLEncode = Str
        End If
    End Function

    '得到字串長度
    Function strlen(ByVal str As String) As Integer
        Dim p_len As Integer
        Dim xx As Integer
        p_len = 0
        strlen = 0
        If Trim(str) <> "" Then '去掉空格
            p_len = Len(Trim(str))
            For xx = 1 To p_len
                If Asc(Mid(str, xx, 1)) < 0 Then
                    strlen = Int(strlen) + 2
                Else
                    strlen = Int(strlen) + 1
                End If
            Next
        End If
    End Function
    '得到標題,如果多於strlen寬度,則以...顯示
    Function gotTopic(ByVal str As String, ByVal strlen1 As String) As String
        Dim l, t, c, i As Integer
        l = Len(str)
        t = 0
        For i = 1 To l
            c = Math.Abs(Asc(Mid(str, i, 1)))
            If c > 255 Then
                t = t + 2
            Else
                t = t + 1
            End If
            If t >= strlen1 Then
                gotTopic = Left(str, i) & "..."
                Exit For
            Else
                gotTopic = str & " "
            End If
        Next
    End Function

    Function RemoveHtml(ByVal str) As String '過濾Html格式
        Dim re As Regex
        str = re.Match(str, "(\<.[^\<]*\>)")
        str = re.Replace(str, " ")
        str = re.Match(str, "(\<\/[^\<]*\>")
        str = re.Replace(str, "")
        RemoveHtml = str
        re = Nothing
    End Function
End Class

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.