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

ASP
利用ASP输出excel文件一例
asp中使用js的encodeURIComponent
ASP动态网站制作中使用MYSQL的分析
如何编写通用的ASP防SQL注入攻击程序
ASP脚本变量、函数、过程和条件语句
ASP内建对象Application和Session
ASP基础教程:常用的 ASP ActiveX 组件
ASP程序漏洞解析及黑客入侵防范方法
ASP访问带多个参数的存储过程
用ASP和SQL语句动态的创建Access表
ASP初学者学习ASP指令
ASP开发中有用的函数(function)集合(1)
ASP开发中有用的函数(function)集合(2)
ASP开发中有用的函数(function)集合(3)
ASP网站程序自动升级实现的方法
ASP开发中的(VBScript)类基础学习
ASP代码:防止重复多次提交表单的方法
在ASP中使用类,实现模块化
ASP基础教程之学习ASP中子程序的应用
ASP技巧:ASP中三个常用语句的使用技巧

ASP中字符串函数的应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 168 ::
收藏到网摘: 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
%>

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