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

ASP
ubb代码的简单实现
在VS.NET中编写Web应用程序(一)
在VS.NET中编写Web应用程序(二)
在VS.NET中编写Web应用程序(三)
ASP.NET编程实例ABC(1)
ASP.NET编程实例ABC(2)
ASP.NET编程实例ABC(3)
亲密接触ASP.Net(8)
亲密接触ASP.Net(9)
ASP.NET重用代码技术 - 代码绑定技术
ASP.NET重用代码技术 - 用户控件技术
在ASP.NET中使用.NET组件
用XSL.ASP编辑XML文档(1)
用XSL.ASP编辑XML文档(2)
亲密接触ASP.Net(10)
亲密接触ASP.Net(11)
亲密接触ASP.Net(12)
亲密接触ASP.Net(13)
亲密接触ASP.Net(14)
亲密接触ASP.Net(15)

ASP中字符串函数的应用


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

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