首页 > 开发 > Asp > 正文

ASP中一个字符串处理类(加强)(VBScript)

2020-02-03 16:41:08
字体:
来源:转载
供稿:网友
相关文章参见:

http://www.csdn.net/develop/read_article.asp?id=22695

本文在此基础上进行了一些添加,加了几个适合中文网站的function进去,可能还有些没有补充进去,有感兴趣的朋友可以再在此基础上加一点function进去,不过可别忘记分享一下!

<%
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
'*******************

||||||
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表