ASP string intercept function

Source: Internet
Author: User

' This article provides the ASP string intercept function is the first to use the definition of string discriminant function to determine the length of the string and the Chinese and English, and then the characters after the interception of the definition beyond the content of ... Display mode

function strvalue (str,lennum)
Dim p_num
Dim i
If strlen (str) <=lennum Then
Strvalue=str
Else
P_num=0
X=0
Do, not p_num > Lennum-2
X=x+1
If ASC (Mid (str,x,1)) <0 Then
P_num=int (P_num) + 2
Else
P_num=int (p_num) + 1
End If
Strvalue=left (Trim (str), x) & "..." ' After interception, define the display mode beyond the content
Loop
End If
End Function

' Define string discriminant function www.111cn.net
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

' Intercept string, 1. Includes front and back strings, 2. Do not include before and after strings
function strcut (strcontent,startstr,endstr,cuttype)
Dim s1,s2
On Error Resume Next
Select Case Cuttype
Case 1
  S1 = InStr (strcontent,startstr)
  s2 = InStr (S1,strcont ENT,ENDSTR) +len (ENDSTR)
Case 2
  S1 = InStr (STRCONTENT,STARTSTR) +len (startstr)
  s2 = InStr (S1, STRCONTENT,ENDSTR)
End Select
If Err then
  Strcute = "<p align= ' center ' ><font size=-1> Intercept string Error .</font></p> '
  err.clear
  Exit Function
Else
  Strcut = Mid (strcontent,s1 , S2-S1)
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.