ASP中一個字符串處理類(加強)(VBScript)
2024-05-04 11:06:13
供稿:網友
相關文章參見:
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
'*******************||||||