asp学习网: 首页 >> asp自定义函数 >> asp自定义函数:截取指定长度的字符串

asp自定义函数:截取指定长度的字符串

'----------------------------------------------------------------'
'    getStrValue
'    截取指定长度字符串
'    参数:
'        str 需要被处理的字符串
'        i    需要保留的字符串长度(一个中文算两个字符长度)
'        str_2 用来表示省略的字符串,例如“…”
'    返回值:字符串 (按要求截取后的字符串)
'----------------------------------------------------------------'
Function getStrValue(ByVal str, ByVal i, ByVal str_2)
    If getStrLen(str) <= i Then
        getStrValue = str
    Else
        Dim j, n, k, chrA
        j = i - getStrLen(str_2)
        n = 0
        k = 0
        Do While n < j
            k = k + 1
            chrA = Mid(str, k, 1)
            If Asc(chrA) < 0 Or Asc(chrA) > 255 Then
                n = n + 2
                If n > j Then k = k - 1
            Else
                n = n + 1
            End If
        Loop
        getStrValue = Left(Trim(str), k) & str_2
    End If
End Function
本函数需要配合 getStrLen 函数使用.参见http://www.aspxuexi.com/code/2006-5-18/function_getStrLen.htm

from:asp学习网/title:asp自定义函数:截取指定长度的字符串/ time:2006-5-18 23:57:56

本文主题asp自定义函数:截取指定长度的字符串

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行