中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > Asp > 综合文章
ASP中一个字符串处理类(VBScript)
作者:asilas 时间:2002-03-23 11:15 出处:互联网 责编:chinaitpower
              摘要:ASP中一个字符串处理类(VBScript)

这个类是用于处理字符串的,是老外写的,我把里面的功能和参数加了说明

使用方法:

=============== 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
%>

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有