国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

ASP中一個字符串處理類(VBScript)

2024-05-04 11:06:15
字體:
供稿:網(wǎng)友
國內(nèi)最大的酷站演示中心!
這個類是用于處理字符串的,是老外寫的,我把里面的功能和參數(shù)加了說明

使用方法:

=============== 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型數(shù)組
'' @參數(shù)說明: - str [string]: 需要轉(zhuǎn)換的字符串
'' @返回值: - [array] char型數(shù)組
'****************************************************************************
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

'****************************************************************************
'' @功能說明: 把一個數(shù)組轉(zhuǎn)換成一個字符串
'' @參數(shù)說明: - arr [array]: 需要轉(zhuǎn)換的數(shù)據(jù)
'' @返回值: - [string] 字符串
'****************************************************************************
public function arraytostring(byval arr)
for i = 0 to ubound(arr)
strobj = strobj & arr(i)
next
arraytostring = strobj
end function

'****************************************************************************
'' @功能說明: 檢查源字符串str是否以chars開頭
'' @參數(shù)說明: - str [string]: 源字符串
'' @參數(shù)說明: - 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結(jié)尾
'' @參數(shù)說明: - str [string]: 源字符串
'' @參數(shù)說明: - 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

'****************************************************************************
'' @功能說明: 復(fù)制n個字符串str
'' @參數(shù)說明: - str [string]: 源字符串
'' @參數(shù)說明: - n [int]: 復(fù)制次數(shù)
'' @返回值: - [string] 復(fù)制后的字符串
'****************************************************************************
public function clone(byval str, n)
for i = 1 to n
value = value & str
next
clone = value
end function

'**************************************************************

|||

最大的網(wǎng)站源碼資源下載站,

**************
'' @功能說明: 刪除源字符串str的前n個字符
'' @參數(shù)說明: - str [string]: 源字符串
'' @參數(shù)說明: - n [int]: 刪除的字符個數(shù)
'' @返回值: - [string] 刪除后的字符串
'****************************************************************************
public function trimstart(byval str, n)
value = mid(str, n+1)
trimstart = value
end function

'****************************************************************************
'' @功能說明: 刪除源字符串str的最后n個字符串
'' @參數(shù)說明: - str [string]: 源字符串
'' @參數(shù)說明: - n [int]: 刪除的字符個數(shù)
'' @返回值: - [string] 刪除后的字符串
'****************************************************************************
public function trimend(byval str, n)
value = left(str, len(str)-n)
trimend = value
end function

'****************************************************************************
'' @功能說明: 檢查字符character是否是英文字符 a-z or a-z
'' @參數(shù)說明: - 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字符串進(jìn)行大小寫轉(zhuǎn)換
'' @參數(shù)說明: - str [string]: 源字符串
'' @返回值: - [string] 轉(zhuǎn)換后的字符串
'****************************************************************************
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中每個單詞的第一個字母轉(zhuǎn)換成大寫
'' @參數(shù)說明: - str [string]: 源字符串
'' @返回值: - [string] 轉(zhuǎn)換后的字符串
'****************************************************************************
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
%>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 巴彦县| 平阳县| 丹凤县| 岢岚县| 金华市| 古田县| 虞城县| 宁海县| 濮阳县| 沅陵县| 温州市| 榕江县| 永顺县| 英超| 内黄县| 福州市| 宜春市| 攀枝花市| 清苑县| 普陀区| 平山县| 乐东| 平顶山市| 屏山县| 南陵县| 曲阜市| 寻乌县| 香格里拉县| 托克托县| 陵水| 无锡市| 余干县| 洪湖市| 西峡县| 商南县| 兴安县| 泰安市| 信宜市| 高淳县| 会同县| 雷山县|