function | string | function | Application of string function in ASP
--------------------------------------------
Author: the Enlightened person
Source: Programming Alliance
Http://www.pgsun.com
Email:liuyong8833@sohu.com
Welcome to study and exchange!
--------------------------------------------
1. String function:
Len (str): Gets the length of the string
Instr (STR1,STR2): From the string str1, look for another string str2 the first occurrence of the position
Left (Str,n): n characters from String str
Right (Str,n): Take n characters from string str
Mid (STR1,N1,N2): Extracts N2 characters starting from the N1 character of the string.
2. String function Application:
1) A string length control function is designed by using the character function:
Prevent line-width string wrapping from exceeding:
<%
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 detect whether the output is an e-mail address through a string function:
<%
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
%>
This detection function is not sufficient and does not detect "." If interested please add.
Programming Alliance
Http://www.pgsun.com