ASP String Intercept function _ Application Tips

Source: Internet
Author: User
ASP string intercept function
'*********************************************************
' Function: Cutstr[str (strlen)]
' Parameters: str, string to be processed, strlen, length of intercept
' Author: wooden Wood
' Date: 2007/7/12
' Description: Intercepts the string of the specified length
' Example: <%=cutstr ("Welcome Arisisi", 5)%>

'*********************************************************

function Cutstr (Str,strlen)
If str = "" Then
CUTSTR = "Cutstr function exception: null string"
Exit function
End If
'------------Source length check
If strlen = "" Then
CUTSTR = "Cutstr function exception: Length not Specified"
Exit function
End If

If CInt (strlen) = 0 Then
CUTSTR = "Cutstr function exception: length 0"
Exit function
End If
'----------Detect source character length
Dim l,t,c,i
L=len (str)
T=0
'----------Circular intercept character
For I=1 to L
C=abs (ASC (str,i,1))
'------judge whether Chinese characters
If c>255 Then
T=t+2
Else
T=t+1
End If
'------determine whether to reach the specified length
If T>=strlen Then
Cutstr=left (str,i) & "..."
Exit For
Else
Cutstr=str
End If
Next
Cutstr=replace (CUTSTR,CHR (10), "")
End Function
''*********************************************************
' Function: Strlen[str]
' Argument: str, the string to be processed
' Author: wooden Wood
' Date: 2007/7/12
' Description: Judge string length, Chinese character length is 2
' Example: <%=strlen ("Welcome to Arisisi")%>
'*********************************************************
Function strlen (str)
Dim P_len
P_len=0
Strlen=0
If Trim (str) <> "" Then
P_len=len (Trim (str))
For Xx=1 to P_len
If ASC (Mid (str,xx,1)) <0 Then
Strlen=int (strlen) + 2
Else
Strlen=int (strlen) + 1
End If
Next
End If
End Function
Intercepts the n characters on the left ' *********************************************************
' Function: Lefttrue (str,n)
' Parameters: str, string to be processed, N, length of interception
' Author: wooden Wood
' Date: 2007/7/12
' Description: Displays the n characters on the left (automatic character recognition) function
' Example: <%=lefttrue ("Welcome Arisisi", 6)%>
'*********************************************************

Function Lefttrue (Str,n)
If len (str) &LT;=N/2 Then
Lefttrue=str
Else
Dim Tstr
Dim L,t,c
Dim I
L=len (str)
T=l
Tstr= ""
T=0
For I=1 to L
C=ASC (Mid (str,i,1))
If C<0 then c=c+65536
If c>255 Then
T=t+2
Else
T=t+1
End If
If t>n Then Exit For
tstr=tstr& (Mid (str,i,1))
Next
Lefttrue = Tstr
End If
End Function


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.