編寫(xiě)asp代碼截取字符串

字號(hào):


    編寫(xiě)asp代碼截取字符串:
    '函數(shù)名:SubstZFC
    '作 用:截字符串,漢字一個(gè)算兩個(gè)字符,英文算一個(gè)字符
    '參 數(shù):str ----原字符串
    ' strlen ----截取長(zhǎng)度
    '返回值:截取后的字符串
    '適用:標(biāo)題截取指定字符,如果用LEFT截取,當(dāng)有英文時(shí)就會(huì)出現(xiàn)取出來(lái)的標(biāo)題明顯太短。
    '**************************************************
    Public Function SubstZFC(ByVal str, ByVal strlen)
    If str = "" Then
    SubstZFC = ""
    Exit Function
    End If
    Dim l, t, c, i, strTemp
    str = Replace(Replace(Replace(Replace(str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
    l = Len(str)
    t = 0
    strTemp = str
    strlen = CLng(strlen)
    For i = 1 To l
    c = Abs(Asc(Mid(str, i, 1)))
    If c > 255 Then
    t = t + 2
    Else
    t = t + 1
    End If
    If t >= strlen Then
    strTemp = Left(str, i)
    Exit For
    End If
    Next
    SubstZFC = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), """), ">", ">"), "<", "<")
    End Function