ASP中一個字串處理類(VBScript) (轉)
這個類是用於處理字串的,是老外寫的,我把裡面的功能和引數加了說明
使用方法:
=============== test.================
<!--#include file="StringOperations.asp"-->
dim str
set str = New StringOperations
test = str.toCharArray("check this out")
response.write "str.toCharArray: "
for i = 0 to ubound(test)
response.write test(i) & " "
next
response.write "
"
test1 = str.arrayToString(test)
response.write "str.arrayToString: " & test1
response.write "
"
response.write "str.startsWith: " & str.startsWith(test1, "ch")
response.write "
"
response.write "str.endWith: " & str.endsWith(test1, "out")
response.write "
"
response.write "str.clone: " & str.clone("abc", 10)
response.write "
"
response.write "str.trimStart: " & str.trimStart(test1, 3)
response.write "
"
response.write "str.trimEnd: " & str.trimEnd(test1, 2)
response.write "
"
response.write "str.sCase: " & str.swapCase("HiHiHi")
response.write "
"
response.write "str.isAlphabetic: " & str.isAlphabetic("!")
response.write "
"
response.write "str.ctalize: " & str.capitalize("clara fehler")
Set str = Nothing
%>
=============== StringOperations.asp================
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
'****************************************************************************
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)
s = 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
end class
%>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-963211/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ASP中令人震撼的Debug類(VBScript) (轉)
- VBScript中引用ASP的字串變數字串變數
- javascript字串處理類JavaScript字串
- 在VBScript中使用類(三) (轉)
- 在VBScript中使用類(四) (轉)
- 【轉載】SHELL字串處理技巧(${}、##、%%)字串
- delphi中的字串處理,以及幾個字串型別的說明。 (轉)字串型別
- JavaScript類似c#字串處理方法format()JavaScriptC#字串ORM
- (轉)Shell常用處理字串方法(備查)字串
- awk 字串處理字串
- abap 字串處理字串
- Java SimpleDateFormat處理日期與字串的轉換JavaORM字串
- 【轉】shell指令碼處理字串的常用方法指令碼字串
- 分享一個圖片處理類
- 30 個 PHP 的 Excel 處理類PHPExcel
- 字串處理工具類字串
- windows批處理之一:字串處理Windows字串
- Java經典例項:處理單個字串Java字串
- jstl處理字串JS字串
- LoadRunner字串處理 - 補齊字串字串
- 取週期性字串中的其中一個字串
- ASP+SQL Server之圖象資料處理 (轉)SQLServer
- WebApi在MVC 4中一個Controll多個post方法報錯處理WebAPIMVC
- Javascrip 之 字串處理 & 定時器 & 型別轉換Java字串定時器型別
- Guava字串處理Joiner、SplitterGuava字串
- PHP 陣列 & 字串處理PHP陣列字串
- shell字串處理總結字串
- 簡單的字串處理字串
- SqlServer——字串處理函式SQLServer字串函式
- 字串的封送處理字串
- shell中字串的處理字串
- 安全字串處理函式字串函式
- GoldenGate COLMAP字串處理Go字串
- 處理字串的小程式字串
- bat 批處理字串操作BAT字串
- 一個專業處理字串的IDEA外掛字串Idea
- 談asp 與SQL server互操作的時間處理 (轉)SQLServer
- 適合於Unix與Win32下的字串處理類,可以以此為基類進行擴充套件 (轉)Win32字串套件