ASP中字符串函数的应用 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- ASP中字符串函数的应用 (http://www.webasp.net/article/26/25768.htm) |
| -- 作者:悟者 -- 发布日期: 2005-07-29 |
| ASP中字符串函数的应用
-------------------------------------------- 作者:悟者 来源:程序设计联盟 http://www.pgsun.com EMAIL:liuyong8833@sohu.com 欢迎前来学习交流! -------------------------------------------- 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 %> 此检测函数并不充分,并没有检测".",如有兴趣请补充。 程序设计联盟 http://www.pgsun.com |
| webasp.net |