国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP中一個字符串處理類加強版

2019-11-17 04:12:50
字體:
來源:轉載
供稿:網友

<%
   class StringOperations

   '***********************************************************************
   '' @功能說明: 把字符串換為char型數組
   '' @參數說明:  - str [string]: 需要轉換的字符串
   '' @返回值:   - [Array] Char型數組
   '************************************************************************
    public function toCharArray(byVal str)
     redim charArray(len(str))
     for i = 1 to len(str)
   charArray(i-1) = Mid(str,i,1)
     next
     toCharArray = charArray
    end function

    '****************************************************************************
    '' @功能說明: 把一個數組轉換成一個字符串
    '' @參數說明:  - arr [Array]: 需要轉換的數據
    '' @返回值:   - [string] 字符串
    '****************************************************************************
    public function arrayToString(byVal arr)
     for i = 0 to UBound(arr)
      strObj = strObj & arr(i)
     next
     varrayToString = strObj
    end function

'****************************************************************************
    '' @功能說明: 檢查源字符串str是否以chars開頭
    '' @參數說明:  - str [string]: 源字符串
    '' @參數說明:  - chars [string]: 比較的字符/字符串
    '' @返回值:   - [bool]
    '****************************************************************************
    public function startsWith(byVal str, chars)
     if Left(str,len(chars)) = chars then
      startsWith = true
     else
      startsWith = false
     end if
    end function

    '****************************************************************************
    '' @功能說明: 檢查源字符串str是否以chars結尾
    '' @參數說明:  - str [string]: 源字符串
    '' @參數說明:  - chars [string]: 比較的字符/字符串
    '' @返回值:   - [bool]
'****************************************************************************
public function endsWith(byVal str, chars)
  if Right(str,len(chars)) = chars then
   endsWith = true
  else
   endsWith = false
  end if
end function

    '****************************************************************************
    '' @功能說明: 復制N個字符串str
    '' @參數說明:  - str [string]: 源字符串
    '' @參數說明:  - n [int]: 復制次數
    '' @返回值:   - [string] 復制后的字符串
    '****************************************************************************
public function clone(byVal str, n)
  for i = 1 to n
   value = value & str
  next
  clone = value
end function

    '****************************************************************************
    '' @功能說明: 刪除源字符串str的前N個字符
    '' @參數說明:  - str [string]: 源字符串
    '' @參數說明:  - n [int]: 刪除的字符個數
    '' @返回值:   - [string] 刪除后的字符串
    '****************************************************************************
public function trimStart(byVal str, n)
  value = Mid(str, n+1)
  trimStart = value
end function

    '****************************************************************************
    '' @功能說明: 刪除源字符串str的最后N個字符串
    '' @參數說明:  - str [string]: 源字符串
    '' @參數說明:  - n [int]: 刪除的字符個數
    '' @返回值:   - [string] 刪除后的字符串
    '****************************************************************************
public function trimEnd(byVal str, n)
  value = Left(str, len(str)-n)
  trimEnd = value
end function

    '****************************************************************************
    '' @功能說明: 檢查字符character是否是英文字符 A-Z or a-z
    '' @參數說明:  - character [char]: 檢查的字符
    '' @返回值:   - [bool] 如果是英文字符,返回TRUE,反之為FALSE
    '****************************************************************************
public function isAlphabetic(byVal character)
  asciiValue = cint(asc(character))
  if (65 <= asciiValue and asciiValue <= 90) or (97 <= asciiValue and asciiValue <= 122) then
   isAlphabetic = true
  else
   isAlphabetic = false
  end if
end function

    '****************************************************************************
    '' @功能說明: 對str字符串進行大小寫轉換
    '' @參數說明:  - str [string]: 源字符串
    '' @返回值:   - [string] 轉換后的字符串
    '****************************************************************************
public function swapCase(str)
  for i = 1 to len(str)
   current = mid(str, i, 1)
   if isAlphabetic(current) then
    high = asc(ucase(current))
    low = asc(lcase(current))
    sum = high + low
    return = return & chr(sum-asc(current))
   else
    return = return & current
   end if
  next
  swapCase = return
end function

    '****************************************************************************
    '' @功能說明: 將源字符串str中每個單詞的第一個字母轉換成大寫
    '' @參數說明:  - str [string]: 源字符串
    '' @返回值:   - [string] 轉換后的字符串
    '****************************************************************************
public function capitalize(str)
  Words = split(str," ")
  for i = 0 to ubound(words)
   if not i = 0 then
    tmp = " "
   end if
   tmp = tmp & ucase(left(words(i), 1)) & right(words(i), len(words(i))-1)
   words(i) = tmp
  next
  capitalize = arrayToString(words)
end function

    '****************************************************************************
    '' @功能說明: 將源字符Str后中的'過濾為''
    '' @參數說明:  - str [string]: 源字符串
    '' @返回值:   - [string] 轉換后的字符串
    '****************************************************************************
public function checkstr(Str)
  If Trim(Str)="" Or IsNull(str) Then
   checkstr=""
  else
   checkstr=Replace(Trim(Str),"'","''")
  end if
End function

'****************************************************************************
    '' @功能說明: 將字符串中的str中的HTML代碼進行過濾
    '' @參數說明:  - str [string]: 源字符串
    '' @返回值:   - [string] 轉換后的字符串
    '****************************************************************************
Public Function HtmlEncode(str)
  If Trim(Str)="" Or IsNull(str) then
   HtmlEncode=""
  else
   str=Replace(str,">",">")
   str=Replace(str,"<","<")
   str=Replace(str,Chr(32)," ")
   str=Replace(str,Chr(9)," ")
   str=Replace(str,Chr(34),""")
   str=Replace(str,Chr(39),"'")
   str=Replace(str,Chr(13),"")
   str=Replace(str,Chr(10) & Chr(10), "</p><p>")
   str=Replace(str,Chr(10),"<br> ")
   HtmlEncode=str
  end if
End Function

    '****************************************************************************
    '' @功能說明: 計算源字符串Str的長度(一個中文字符為2個字節長)
    '' @參數說明:  - str [string]: 源字符串
    '' @返回值:   - [Int] 源字符串的長度
    '****************************************************************************
Public Function strLen(Str)
  If Trim(Str)="" Or IsNull(str) Then
   strlen=0
  else
   Dim P_len,x
   P_len=0
   StrLen=0
   P_len=Len(Trim(Str))
   For x=1 To P_len
    If Asc(Mid(Str,x,1))<0 Then
     StrLen=Int(StrLen) + 2
    Else
     StrLen=Int(StrLen) + 1
    End If
   Next
  end if
End Function

'****************************************************************************
    '' @功能說明: 截取源字符串Str的前LenNum個字符(一個中文字符為2個字節長)
    '' @參數說明:  - str [string]: 源字符串
    '' @參數說明:  - LenNum [int]: 截取的長度
    '' @返回值:   - [string]: 轉換后的字符串
    '****************************************************************************
Public Function CutStr(Str,LenNum)
  Dim P_num
  Dim I,X
  If StrLen(Str)<=LenNum Then
   Cutstr=Str
  Else
   P_num=0
   X=0
   Do While Not P_num > LenNum-2
    X=X+1
    If Asc(Mid(Str,X,1))<0 Then
     P_num=Int(P_num) + 2
    Else
     P_num=Int(P_num) + 1
    End If
    Cutstr=Left(Trim(Str),X)&"..."
   Loop
  End If
End Function

end class
%>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 崇仁县| 容城县| 兴隆县| 屯昌县| 新田县| 石城县| 上高县| 弥勒县| 金乡县| 理塘县| 那曲县| 新河县| 侯马市| 阳泉市| 蛟河市| 南涧| 靖安县| 新津县| 孟津县| 漳浦县| 横山县| 金门县| 太保市| 东阿县| 桦南县| 安岳县| 布尔津县| 鹰潭市| 闸北区| 库车县| 静宁县| 板桥市| 同心县| 上思县| 尤溪县| 顺义区| 八宿县| 渭源县| 正蓝旗| 磐石市| 秦皇岛市|