vbscript|字串|vbscript|字串 相關文章參見:
http://www.csdn.net/Develop/read_article.asp?id=22695
本文在此基礎上進行了一些添加,加了幾個適合中文網站的FUNCTION進去,可能還有些沒有補充進去,有感興趣的朋友可以再在此基礎上加一點FUNCTION進去,不過可別忘記分享一下!
<%
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
arrayToString = 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
'*******************
[1] [2] [3] 下一頁