最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP中一个字符串处理类加强版技巧

日期:10-19    来源:中国设计秀    作者:cnwebshow.com

<%HaK中国设计秀
   class StringOperationsHaK中国设计秀

   '***********************************************************************HaK中国设计秀
   '' @功能说明: 把字符串换为char型数组HaK中国设计秀
   '' @参数说明:  - str [string]: 需要转换的字符串HaK中国设计秀
   '' @返回值:   - [Array] Char型数组HaK中国设计秀
   '************************************************************************HaK中国设计秀
    public function toCharArray(byVal str)HaK中国设计秀
     redim charArray(len(str))HaK中国设计秀
     for i = 1 to len(str)HaK中国设计秀
   charArray(i-1) = Mid(str,i,1)HaK中国设计秀
     nextHaK中国设计秀
     toCharArray = charArrayHaK中国设计秀
    end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 把一个数组转换成一个字符串HaK中国设计秀
    '' @参数说明:  - arr [Array]: 需要转换的数据HaK中国设计秀
    '' @返回值:   - [string] 字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
    public function arrayToString(byVal arr)HaK中国设计秀
     for i = 0 to UBound(arr)HaK中国设计秀
      strObj = strObj & arr(i)HaK中国设计秀
     nextHaK中国设计秀
     varrayToString = strObjHaK中国设计秀
    end functionHaK中国设计秀

'****************************************************************************HaK中国设计秀
    '' @功能说明: 检查源字符串str是否以chars开头HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @参数说明:  - chars [string]: 比较的字符/字符串HaK中国设计秀
    '' @返回值:   - [bool] HaK中国设计秀
    '****************************************************************************HaK中国设计秀
    public function startsWith(byVal str, chars)HaK中国设计秀
     if Left(str,len(chars)) = chars thenHaK中国设计秀
      startsWith = trueHaK中国设计秀
     elseHaK中国设计秀
      startsWith = falseHaK中国设计秀
     end ifHaK中国设计秀
    end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 检查源字符串str是否以chars结尾HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @参数说明:  - chars [string]: 比较的字符/字符串HaK中国设计秀
    '' @返回值:   - [bool] HaK中国设计秀
'****************************************************************************HaK中国设计秀
public function endsWith(byVal str, chars)HaK中国设计秀
  if Right(str,len(chars)) = chars thenHaK中国设计秀
   endsWith = trueHaK中国设计秀
  elseHaK中国设计秀
   endsWith = falseHaK中国设计秀
  end ifHaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 复制N个字符串strHaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @参数说明:  - n [int]: 复制次数HaK中国设计秀
    '' @返回值:   - [string] 复制后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function clone(byVal str, n)HaK中国设计秀
  for i = 1 to nHaK中国设计秀
   value = value & strHaK中国设计秀
  nextHaK中国设计秀
  clone = valueHaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 删除源字符串str的前N个字符HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @参数说明:  - n [int]: 删除的字符个数HaK中国设计秀
    '' @返回值:   - [string] 删除后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function trimStart(byVal str, n)HaK中国设计秀
  value = Mid(str, n+1)HaK中国设计秀
  trimStart = valueHaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 删除源字符串str的最后N个字符串HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @参数说明:  - n [int]: 删除的字符个数HaK中国设计秀
    '' @返回值:   - [string] 删除后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function trimEnd(byVal str, n)HaK中国设计秀
  value = Left(str, len(str)-n)HaK中国设计秀
  trimEnd = valueHaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 检查字符character是否是英文字符 A-Z or a-zHaK中国设计秀
    '' @参数说明:  - character [char]: 检查的字符HaK中国设计秀
    '' @返回值:   - [bool] 如果是英文字符,返回TRUE,反之为FALSEHaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function isAlphabetic(byVal character)HaK中国设计秀
  asciiValue = cint(asc(character))HaK中国设计秀
  if (65 <= asciiValue and asciiValue <= 90) or (97 <= asciiValue and asciiValue <= 122) thenHaK中国设计秀
   isAlphabetic = trueHaK中国设计秀
  elseHaK中国设计秀
   isAlphabetic = falseHaK中国设计秀
  end ifHaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 对str字符串进行大小写转换HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @返回值:   - [string] 转换后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function swapCase(str)HaK中国设计秀
  for i = 1 to len(str)HaK中国设计秀
   current = mid(str, i, 1)HaK中国设计秀
   if isAlphabetic(current) thenHaK中国设计秀
    high = asc(ucase(current))HaK中国设计秀
    low = asc(lcase(current))HaK中国设计秀
    sum = high + lowHaK中国设计秀
    return = return & chr(sum-asc(current))HaK中国设计秀
   elseHaK中国设计秀
    return = return & currentHaK中国设计秀
   end ifHaK中国设计秀
  nextHaK中国设计秀
  swapCase = returnHaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 将源字符串str中每个单词的第一个字母转换成大写HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @返回值:   - [string] 转换后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function capitalize(str)HaK中国设计秀
  words = split(str," ")HaK中国设计秀
  for i = 0 to ubound(words)HaK中国设计秀
   if not i = 0 thenHaK中国设计秀
    tmp = " "HaK中国设计秀
   end ifHaK中国设计秀
   tmp = tmp & ucase(left(words(i), 1)) & right(words(i), len(words(i))-1)HaK中国设计秀
   words(i) = tmpHaK中国设计秀
  nextHaK中国设计秀
  capitalize = arrayToString(words)HaK中国设计秀
end functionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 将源字符Str后中的'过滤为''HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @返回值:   - [string] 转换后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
public function checkstr(Str)HaK中国设计秀
  If Trim(Str)="" Or IsNull(str) Then HaK中国设计秀
   checkstr=""HaK中国设计秀
  elseHaK中国设计秀
   checkstr=Replace(Trim(Str),"'","''")HaK中国设计秀
  end ifHaK中国设计秀
End functionHaK中国设计秀

'****************************************************************************HaK中国设计秀
    '' @功能说明: 将字符串中的str中的HTML代码进行过滤HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @返回值:   - [string] 转换后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
Public Function HtmlEncode(str)HaK中国设计秀
  If Trim(Str)="" Or IsNull(str) thenHaK中国设计秀
   HtmlEncode=""HaK中国设计秀
  elseHaK中国设计秀
   str=Replace(str,">",">")HaK中国设计秀
   str=Replace(str,"<","<")HaK中国设计秀
   str=Replace(str,Chr(32)," ")HaK中国设计秀
   str=Replace(str,Chr(9)," ")HaK中国设计秀
   str=Replace(str,Chr(34),""")HaK中国设计秀
   str=Replace(str,Chr(39),"'")HaK中国设计秀
   str=Replace(str,Chr(13),"")HaK中国设计秀
   str=Replace(str,Chr(10) & Chr(10), "</p><p>")HaK中国设计秀
   str=Replace(str,Chr(10),"<br> ")HaK中国设计秀
   HtmlEncode=strHaK中国设计秀
  end ifHaK中国设计秀
End FunctionHaK中国设计秀

    '****************************************************************************HaK中国设计秀
    '' @功能说明: 计算源字符串Str的长度(一个中文字符为2个字节长)HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @返回值:   - [Int] 源字符串的长度HaK中国设计秀
    '****************************************************************************HaK中国设计秀
Public Function strLen(Str)HaK中国设计秀
  If Trim(Str)="" Or IsNull(str) Then HaK中国设计秀
   strlen=0HaK中国设计秀
  elseHaK中国设计秀
   Dim P_len,xHaK中国设计秀
   P_len=0HaK中国设计秀
   StrLen=0HaK中国设计秀
   P_len=Len(Trim(Str))HaK中国设计秀
   For x=1 To P_lenHaK中国设计秀
    If Asc(Mid(Str,x,1))<0 ThenHaK中国设计秀
     StrLen=Int(StrLen) + 2HaK中国设计秀
    ElseHaK中国设计秀
     StrLen=Int(StrLen) + 1HaK中国设计秀
    End IfHaK中国设计秀
   NextHaK中国设计秀
  end ifHaK中国设计秀
End FunctionHaK中国设计秀

'****************************************************************************HaK中国设计秀
    '' @功能说明: 截取源字符串Str的前LenNum个字符(一个中文字符为2个字节长)HaK中国设计秀
    '' @参数说明:  - str [string]: 源字符串HaK中国设计秀
    '' @参数说明:  - LenNum [int]: 截取的长度HaK中国设计秀
    '' @返回值:   - [string]: 转换后的字符串HaK中国设计秀
    '****************************************************************************HaK中国设计秀
Public Function CutStr(Str,LenNum)HaK中国设计秀
  Dim P_numHaK中国设计秀
  Dim I,XHaK中国设计秀
  If StrLen(Str)<=LenNum ThenHaK中国设计秀
   Cutstr=StrHaK中国设计秀
  ElseHaK中国设计秀
   P_num=0HaK中国设计秀
   X=0HaK中国设计秀
   Do While Not P_num > LenNum-2HaK中国设计秀
    X=X+1HaK中国设计秀
    If Asc(Mid(Str,X,1))<0 ThenHaK中国设计秀
     P_num=Int(P_num) + 2HaK中国设计秀
    ElseHaK中国设计秀
     P_num=Int(P_num) + 1HaK中国设计秀
    End IfHaK中国设计秀
    Cutstr=Left(Trim(Str),X)&"..."HaK中国设计秀
   LoopHaK中国设计秀
  End IfHaK中国设计秀
End FunctionHaK中国设计秀

end classHaK中国设计秀
%>HaK中国设计秀

本文引用地址:/bc/article_46248.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明