- 热门文章:
- · WEB环境下办公自动化文档修改痕迹保留的实现
- · 用stream读文件
- · ASP初学者参考!
- · 关于asp调试出错信息
- · 对文件夹操作2
- · 对文件的操作1
- · 如何动态ASP文件
- · 不用组件的简单分页
- · 鼠标在文本上移动时层的显示与消失
- · ASP 编程中 20 个非常有用的例子——适合初学者
- · 什么是Global.asa文件
- · ASP初学者怎样快速入门
上一篇:整理了一些ASP初学者常用的代码 >>
ASP中一个字符串处理类(加强)(VBScript)
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
‘’****************************************************************************
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
‘’****************************************************************************
‘’‘’ @功能说明: 将源字符Str后中的‘’过滤为‘’‘’
‘’‘’ @参数说明: - str [string]: 源字符串
‘’‘’ @返回值: - [string] 转换后的字符串
‘’****************************************************************************
public function checkstr(Str)
If Trim(Str)="" Or IsNull(str) Then
checkstr=""
else
checkstr=Replace(Trim(Str),"‘’","‘’‘’")
end if
End function
‘’****************************************************************************
‘’‘’ @功能说明: 将字符串中的str中的HTML代码进行过滤
‘’‘’ @参数说明: - str [string]: 源字符串
‘’‘’ @返回值: - [string] 转换后的字符串
‘’****************************************************************************
Public Function HtmlEncode(str)
If Trim(Str)="" Or IsNull(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
end if
End Function
‘’****************************************************************************
‘’‘’ @功能说明: 计算源字符串Str的长度(一个中文字符为2个字节长)
‘’‘’ @参数说明: - str [string]: 源字符串
‘’‘’ @返回值: - [Int] 源字符串的长度
‘’****************************************************************************
Public Function strLen(Str)
If Trim(Str)="" Or IsNull(str) Then
strlen=0
else
Dim P_len,x
P_len=0
StrLen=0
P_len=Len(Trim(Str))
For x=1 To P_len
If Asc(Mid(Str,x,1))<0 Then
StrLen=Int(StrLen) + 2
Else
StrLen=Int(StrLen) + 1
End If
Next
end if
End Function
‘’****************************************************************************
‘’‘’ @功能说明: 截取源字符串Str的前LenNum个字符(一个中文字符为2个字节长)
‘’‘’ @参数说明: - str [string]: 源字符串
‘’‘’ @参数说明: - LenNum [int]: 截取的长度
‘’‘’ @返回值: - [string]: 转换后的字符串
‘’****************************************************************************
Public Function CutStr(Str,LenNum)
Dim P_num
Dim I,X
If StrLen(Str)<=LenNum Then
Cutstr=Str
Else
P_num=0
X=0
Do While Not P_num > LenNum-2
X=X+1
If Asc(Mid(Str,X,1))<0 Then
P_num=Int(P_num) + 2
Else
P_num=Int(P_num) + 1
End If
Cutstr=Left(Trim(Str),X)&"..."
Loop
End If
End Function
end class
%>
下一篇:WEB环境下办公自动化文档修改痕迹保留的实现 >>
相关文章:
- · asp学习入门经验谈
- · 关于#include的说明
- · 跟我学做留言本(二)
- · 遍历目录以及目录下文件的函数
- · 如何取得所有的Session变量
- · 函数型显示翻页连接
- · 关于错误信息的显示
- · 怎样开始一个ASP网站的设计
- · 网络程序设计中的模块化思维
- · DHTML对象模型(About the DHTML Object Model)(三)
- · DHTML对象模型(About the DHTML Object Model)(二)
- · DHTML对象模型(About the DHTML Object Model)(一)
- · ASP六大对象介绍(2)
- · ASP六大对象介绍(1)
- · china.com网站编辑规范(2)
- · China.com网站开发规范(1)
- · 中国高校勤工助学网站程序开发质量和管理标准化
- · 按钮链接乾坤大挪移
- · VBScript函数补习课
- · ASP之对象总结
- · 错误80004005信息处理方法
- · ASP问答集
- · MicrosoftVBscript运行时错误(完整版)共121个
- · Asp设计常见问题及解答精要
- · 程序员应具备的素质
- · 我学习ASP、网页制作中的几点心得~(参考)
- · 在VBScript中使用类(四)
- · 在VBScript中使用类(三)
- · 错误80004005信息处理又一方法
- · 在VBScript中使用类(二)
- · 在VBScript中使用类(一)
- · 常用Response对象的使用祥解
- · session和cookie的最深刻理解
- · 利用客户端js实现汉字简体繁体转换
- · asp程序错误详细说明例表
- · 简单WEB开发规范
- · asp程序错误详细说明例表
- · HTA的简单应用
