ASP string intercept function, suitable for acquisition program call

Source: Internet
Author: User
Tags contains end first string include string split
'********************************************************************************
' Function (public)
' Name: string intercept function
' Function: intercept content by specified end-end string (This function is truncated from left to right)
' Parameters: scontent----intercepted content
' Sstart------First string
' Istartno----When the first string is not unique, take the first few
' Bincstart---Contains the first string (1/true is included, 0/false is not included)
' Istartcusor-first offset value (number of characters in pointer, negative for left, positive for right bias, 0)
' Sover-------Tail string
' Ioverno-----When the tail string is not unique, take the first few
' bincover----include the tail string (1/true is included, 0/false is not included)
' Iovercusor--tail offset value (number of characters in pointer, negative for left, positive for right bias, 0)
'********************************************************************************
Public Function senfe_cut (scontent, Sstart, Istartno, Bincstart, Istartcusor, Sover, Ioverno, Bincover, Iovercusor)
If scontent<> "" Then
Dim Istartlen, Ioverlen, IStart, Iover, Istartcount, Iovercount, I
Istartlen = Len (sstart) ' first string length
Ioverlen = Len (sover) ' Tail string length
The first occurrence of the first string
IStart = InStr (scontent, Sstart)
' The first occurrence of the tail string on the right side of the first string
Iover = InStr (IStart + Istartlen, scontent, Sover)
If istart>0 and Iover>0 Then
If Istartno < 1 Or isnumeric (istartno) =false Then Istartno = 1
If Ioverno < 1 Or isnumeric (ioverno) =false Then Ioverno = 1
' Gets the number of occurrences of the first string
Istartcount = UBound (Split (scontent, Sstart))
If istartno>1 and Istartcount>0 Then
If istartno>istartcount Then Istartno = Istartcount
For I = 1 to Istartno
IStart = InStr (IStart, Scontent, Sstart) + Istartlen
Next
Iover = InStr (IStart, scontent, Sover)
IStart = Istart-istartlen ' restore default state: Contains a first string
End If
' Gets the number of times the tail string appears
Iovercount = UBound (Split (Mid (scontent, IStart + istartlen), sover))
If ioverno>1 and Iovercount>0 Then
If ioverno>iovercount Then Ioverno = Iovercount
For I=1 to Ioverno
Iover = InStr (Iover, Scontent, sover) + Ioverlen
Next
Iover = Iover-ioverlen ' restore default state: Does not include tail string
End If
If CBool (bincstart) =false Then iStart = iStart + Istartlen ' does not contain a first string
If CBool (bincover) Then iover = iover + Ioverlen ' contains tail string
IStart = IStart + istartcusor ' plus first offset value
Iover = iover + iovercusor ' plus tail offset value
If istart<1 Then IStart = 1
If iover<=istart Then iover = iStart + 1
' Intercept content at specified start and end locations
Senfe_cut = Mid (scontent, IStart, Iover-istart)
Else
' Senfe_cut = scontent
Senfe_cut = "did not find the content you want, you may set the end of the string does not exist!" "
End If
Else
Senfe_cut = "No content!" "
End If
End Function


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.