The application of string function in ASP

Source: Internet
Author: User
Tags string
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



Related Article

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.