当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP中字符串函数的应用

ASP
ASP XML操作类代码
asp读取xml实例代码
ASP读取XML实例 优酷专辑采集程序 雷锋版
asp自带的内存缓存 application
Cookies 欺骗漏洞的防范方法(vbs+js 实现)
asp清理缓存的代码
asp Driver和Provider两种连接字符串连接Access时的区别
asp 性能测试报告 学习asp朋友需要了解的东西
ASP实例代码:asp操作Excel类
ASP 高亮显示不区分大小写的关键字
ASP XMLDom在服务器端操作XML文件的主要方法和实现
IE8内部对渲染模型的判断流程
web开发人员必须知道的Unicode与字符集相关知识

ASP中字符串函数的应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 25 ::
收藏到网摘: n/a

1. 字符串函数:
Len(str):取得字符串的长度
Instr(str1,str2):从字符串str1,寻找另一个字符串str2第一个出现的位置
Left(str,n):从字符串str左起取n个字符
Right(str,n):从字符串str右起取n个字符
Mid(str1,n1,n2):从字符串第n1个字符开始,取出n2个字符。

2.字符串函数应用:
1)通过字符函数设计出一个字符串长度控制函数:
防止超过行宽字符串换行:

<%
 Function strleft(string,leng)
   Dim str1
   Dim i,j,k
   j = Len(string)
   k = 0
   For i = 1 To j
     str1 = Mid(string,i,1)
     If Asc(str1) > 0 Then
       k = k + 1
     Else
       k = k + 2
     End If
     If k > leng Then
       strLeft = Left(string,i) & "..."
       Exit For
     Else
       strLeft = string
     End If
   Next
  End Function
%>

2)通过字符串函数检测输出是否为电子邮件地址:

<%
 Function EMAIL(string)
   Dim str1
   Dim i,j,k,l
   j = Len(string)
   k = 0
   for i = 1 to j
     str1=Mid(string,i,1)
  if str1 = "@" then
  k = k + 1
  l = i
  end if
   next
   str2 = Mid(string,l+1,1)
   if (k=1) And ((str2>="a") And (str2<="z")) or ((str2>="A") And (str2<="Z")) then
   EMAIL = string
   else
   EMAIL = "miss!"
   end if
 End Function
%>

此检测函数并不充分,并没有检测".",如有兴趣请补充。