Thread: Strip function?

    #1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    69
    Rep Power
    5

    Strip function?


    Hi guys

    I sincerely hope you can help. In my classic ASP page I need a function (or functions) that will do two things.

    a) Firstly, strip a certain number of words from the end of a string. For example:

    mystring = "the quick brown fox jumped over the lazy dog"

    would display as

    "the quick brown fox"

    if I used something like this:

    <%=mytrim(mystring, 5)%>


    b) Secondly, strip a certain number of words from the beginning of a string. For example

    myotherstring = "the quick brown fox jumped over the lazy dog"

    would display as

    "jumped over the lazy dog"

    if I used something like this:

    <%=myothertrim(myotherstring, 4)%>

    Does this make sense? If so, is it possible and if so, how on earth is it done in classic ASP?

    Any help would be fully appreciated

    Best regards

    Rod from the UK

    PS: The closest I got was this (see below) but I couldn't get it to work the other way:

    <%
    Function TrimIt(sInput, iLength)
    Dim aWords, iCounter, sOutput, sTmp

    sOutput = sInput

    If InStr(sInput, " ") > 0 Then
    aWords = Split(sInput, " ")
    For iCounter = 0 To UBound(aWords)
    If Len(aWords(iCounter) & " ") + Len(sTmp) <= iLength Then
    sTmp = sTmp & " " & aWords(iCounter)
    Else
    Exit For
    End If
    Next
    sOutput = sTmp
    End If

    TrimIt = sOutput + "..."
    End Function
    %>

    <%=TrimIt(description, 150)%>
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0
    function mytrim(v1, v2)
    mytrim = left(v1, v2) ' this will bring v2 characters from left to right of v1 string
    end function

    function myothertrim(v1, v2)
    myothertrim = right(v1, v2) ' this will bring v2 characters from rigto to left of v1 string
    end function

Similar Threads

  1. Replies: 5
    Last Post: April 29th, 2008, 08:32 AM
  2. Replies: 1
    Last Post: September 13th, 2006, 12:07 PM
  3. Strip last character
    By bdensmore in forum ASP Development
    Replies: 3
    Last Post: December 21st, 2005, 05:50 PM
  4. Strip HTML Tags function - Unexpected Quantifier
    By jonathen in forum ASP Development
    Replies: 15
    Last Post: August 17th, 2004, 07:15 AM
  5. Strip Non-Numeric characters from string function
    By ricksterval in forum Code Bank
    Replies: 0
    Last Post: February 12th, 2004, 10:48 AM

IMN logo majestic logo threadwatch logo seochat tools logo