手机
当前位置:查字典教程网 >编程开发 >ASP教程 >ASP中一个字符串处理类
ASP中一个字符串处理类
摘要:复制代码代码如下:

复制代码 代码如下:

<%

classStringOperations

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

''''@功能说明:把字符串换为char型数组

''''@参数说明:-str[string]:需要转换的字符串

''''@返回值:-[Array]Char型数组

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

publicfunctiontoCharArray(byValstr)

redimcharArray(len(str))

fori=1tolen(str)

charArray(i-1)=Mid(str,i,1)

next

toCharArray=charArray

endfunction

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

''''@功能说明:把一个数组转换成一个字符串

''''@参数说明:-arr[Array]:需要转换的数据

''''@返回值:-[string]字符串

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

publicfunctionarrayToString(byValarr)

fori=0toUBound(arr)

strObj=strObj&arr(i)

next

arrayToString=strObj

endfunction

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

''''@功能说明:检查源字符串str是否以chars开头

''''@参数说明:-str[string]:源字符串

''''@参数说明:-chars[string]:比较的字符/字符串

''''@返回值:-[bool]

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

publicfunctionstartsWith(byValstr,chars)

ifLeft(str,len(chars))=charsthen

startsWith=true

else

startsWith=false

endif

endfunction

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

''''@功能说明:检查源字符串str是否以chars结尾

''''@参数说明:-str[string]:源字符串

''''@参数说明:-chars[string]:比较的字符/字符串

''''@返回值:-[bool]

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

publicfunctionendsWith(byValstr,chars)

ifRight(str,len(chars))=charsthen

endsWith=true

else

endsWith=false

endif

endfunction

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

''''@功能说明:复制N个字符串str

''''@参数说明:-str[string]:源字符串

''''@参数说明:-n[int]:复制次数

''''@返回值:-[string]复制后的字符串

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

publicfunctionclone(byValstr,n)

fori=1ton

value=value&str

next

clone=value

endfunction

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

''''@功能说明:删除源字符串str的前N个字符

''''@参数说明:-str[string]:源字符串

''''@参数说明:-n[int]:删除的字符个数

''''@返回值:-[string]删除后的字符串

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

publicfunctiontrimStart(byValstr,n)

value=Mid(str,n+1)

trimStart=value

endfunction

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

''''@功能说明:删除源字符串str的最后N个字符串

''''@参数说明:-str[string]:源字符串

''''@参数说明:-n[int]:删除的字符个数

''''@返回值:-[string]删除后的字符串

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

publicfunctiontrimEnd(byValstr,n)

value=Left(str,len(str)-n)

trimEnd=value

endfunction

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

''''@功能说明:检查字符character是否是英文字符A-Zora-z

''''@参数说明:-character[char]:检查的字符

''''@返回值:-[bool]如果是英文字符,返回TRUE,反之为FALSE

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

publicfunctionisAlphabetic(byValcharacter)

asciiValue=cint(asc(character))

if(65<=asciiValueandasciiValue<=90)or(97<=asciiValueandasciiValue<=122)then

isAlphabetic=true

else

isAlphabetic=false

endif

endfunction

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

''''@功能说明:对str字符串进行大小写转换

''''@参数说明:-str[string]:源字符串

''''@返回值:-[string]转换后的字符串

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

publicfunctionswapCase(str)

fori=1tolen(str)

current=mid(str,i,1)

ifisAlphabetic(current)then

high=asc(ucase(current))

low=asc(lcase(current))

sum=high+low

return=return&chr(sum-asc(current))

else

return=return¤t

endif

next

swapCase=return

endfunction

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

''''@功能说明:将源字符串str中每个单词的第一个字母转换成大写

''''@参数说明:-str[string]:源字符串

''''@返回值:-[string]转换后的字符串

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

publicfunctioncapitalize(str)

words=split(str,"")

fori=0toubound(words)

ifnoti=0then

tmp=""

endif

tmp=tmp&ucase(left(words(i),1))&right(words(i),len(words(i))-1)

words(i)=tmp

next

capitalize=arrayToString(words)

endfunction

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

''''@功能说明:将源字符Str后中的''过滤为''''

''''@参数说明:-str[string]:源字符串

''''@返回值:-[string]转换后的字符串

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

publicfunctioncheckstr(Str)

IfTrim(Str)=""OrIsNull(str)Then

checkstr=""

else

checkstr=Replace(Trim(Str),"''","''''")

endif

Endfunction

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

''''@功能说明:将字符串中的str中的HTML代码进行过滤

''''@参数说明:-str[string]:源字符串

''''@返回值:-[string]转换后的字符串

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

PublicFunctionHtmlEncode(str)

IfTrim(Str)=""OrIsNull(str)then

HtmlEncode=""

else

str=Replace(str,">",">")

str=Replace(str,"<","<")

str=Replace(str,Chr(32),"")

str=Replace(str,Chr(9),"")

str=Replace(str,Chr(34),""")

str=Replace(str,Chr(39),"'")

str=Replace(str,Chr(13),"")

str=Replace(str,Chr(10)&Chr(10),"</p><p>")

str=Replace(str,Chr(10),"<br>")

HtmlEncode=str

endif

EndFunction

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

''''@功能说明:计算源字符串Str的长度(一个中文字符为2个字节长)

''''@参数说明:-str[string]:源字符串

''''@返回值:-[Int]源字符串的长度

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

PublicFunctionstrLen(Str)

IfTrim(Str)=""OrIsNull(str)Then

strlen=0

else

DimP_len,x

P_len=0

StrLen=0

P_len=Len(Trim(Str))

Forx=1ToP_len

IfAsc(Mid(Str,x,1))<0Then

StrLen=Int(StrLen)+2

Else

StrLen=Int(StrLen)+1

EndIf

Next

endif

EndFunction

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

''''@功能说明:截取源字符串Str的前LenNum个字符(一个中文字符为2个字节长)

''''@参数说明:-str[string]:源字符串

''''@参数说明:-LenNum[int]:截取的长度

''''@返回值:-[string]:转换后的字符串

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

PublicFunctionCutStr(Str,LenNum)

DimP_num

DimI,X

IfStrLen(Str)<=LenNumThen

Cutstr=Str

Else

P_num=0

X=0

DoWhileNotP_num>LenNum-2

X=X+1

IfAsc(Mid(Str,X,1))<0Then

P_num=Int(P_num)+2

Else

P_num=Int(P_num)+1

EndIf

Cutstr=Left(Trim(Str),X)&"..."

Loop

EndIf

EndFunction

endclass

%>

【ASP中一个字符串处理类】相关文章:

如何编写一个ASP类

ASP中一个用VBScript写的随机数类

ASP常用的几个功能模块

ASP中处置#include

利用ASP发送和接收XML数据的处理方法

获取字符中中文首字字符

ASP与PHP的不同之处

限制一个Ip只能访问一次的asp代码

ASP中如何判断一个字符是不是汉字

Asp事务处理

精品推荐
分类导航