ASP string intercept function

Source: Internet
Author: User
Tags strlen trim

             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 Chinese and English, and then intercept the characters after 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 While not p_num > Lennum-2
           x=x+1
            if ASC (Mid (str,x,1)) <0 then
         &nBsp;  p_num=int (P_num) + 2
           else
           p_num=int (p_num) + 1
            end if
            strvalue=left (Trim (str), x) & "..." ' After intercepting the display of the content beyond the definition
           loop
            end if
            end function

            ' Define string discriminant functions

           function strlen (str)
            dim P_len
            p_len=0
           strlen=0
           if trim (str) <> "" Then
            p_len=len ((str))
            for xx=1 to P_len
            if ASC (Mid (str,xx,1)) <0 then
            strlen=int (strlen) + 2
           else
            strlen=int (strlen) + 1
    & nbsp;       end if
            next
           end If
            end function

            ' intercepts the 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,STRCONTENT,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> intercepting string error. </font></p >
             err.clear
              Exit Function
            else
              strcut = Mid (strcontent,s1,s2-s1)
            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.