Application of string functions in ASP

Source: Internet
Author: User
Application of string functions in ASP
--------------------------------------------
Author: enlightened
Source: Program Design Alliance
Http://www.pgsun.com
EMAIL: liuyong8833@sohu.com
Welcome to learn and exchange!
--------------------------------------------
1. String functions:
Len (str): Gets the length of a string.
Instr (str1, str2): find the first position of str2 from str1.
Left (str, n): n characters from the Left of the str string
Right (str, n): Gets n characters from the Right of the string str
Mid (str1, n1, n2): removes n2 characters starting from the n1 character of the string.
2. String function application:
1) use the character function to design a string length control function:
Avoid line feed when the line width is exceeded:
<%
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
Else
StrLeft = string
End If
Next
End Function
%>
2) use the string function to check whether the output is an email address:
<%
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> = "") and (str2 <= "Z") then
EMAIL = string
Else
EMAIL = "miss! "
End if
End Function
%>
This detection function is inadequate and does not detect ".". If you are interested, add it.
Program Design Alliance
Http://www.pgsun.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.