ASPい才﹃矪瞶摸VBScript

- い瓣WEB秨祇呼蹈 (http://www.webasp.net)
-- м砃毙祘 (http://www.webasp.net/article/)
--- ASPい才﹃矪瞶摸VBScript (http://www.webasp.net/article/8/7972.htm)
-- ゼ
-- 祇ら戳 2003-12-19
硂摸琌ノ矪瞶才﹃琌ρ糶ир柑㎝把计弧

ㄏノよ猭

=============== test.asp================

<!--#include file="StringOperations.asp"-->

<%
dim str
set str = New StringOperations
test = str.toCharArray("check this out")
response.write "<strong>str.toCharArray</strong>: "
for i = 0 to ubound(test)
response.write test(i) & " "
next

response.write "<BR><BR>"
test1 = str.arrayToString(test)
response.write "<strong>str.arrayToString</strong>: " & test1

response.write "<BR><BR>"
response.write "<strong>str.startsWith</strong>: " & str.startsWith(test1, "ch")

response.write "<BR><BR>"
response.write "<strong>str.endWith</strong>: " & str.endsWith(test1, "out")

response.write "<BR><BR>"
response.write "<strong>str.clone</strong>: " & str.clone("abc", 10)

response.write "<BR><BR>"
response.write "<strong>str.trimStart</strong>: " & str.trimStart(test1, 3)

response.write "<BR><BR>"
response.write "<strong>str.trimEnd</strong>: " & str.trimEnd(test1, 2)

response.write "<BR><BR>"
response.write "<strong>str.swapCase</strong>: " & str.swapCase("HiHiHi")

response.write "<BR><BR>"
response.write "<strong>str.isAlphabetic</strong>: " & str.isAlphabetic("!")

response.write "<BR><BR>"
response.write "<strong>str.capitalize</strong>: " & 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)
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

end class
%>


webasp.net