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 |