Solved

Need to trim off last two characters on the right

Posted on 2004-10-21
1,564 Views
Last Modified: 2008-06-29
For example - I have a sku called 1102301 and I need to return the value of 11023 without the 01.  Is there a way to do this in asp?  I tried using the rtrim but I keep getting errors.

Thanks!

0
Question by:foreverdita
    5 Comments
     

    Author Comment

    by:foreverdita
    I should also add that the skus are all different lengths - example:

    1102301
    134202
    154231109

    (where I still need to trim the last two numbers from the end)

    0
     
    LVL 7

    Accepted Solution

    by:
    rtrim is to remove spaces.

    you probably would want to use left

    <% =Left("11023", len(yourSKU) - 2) %>

    If you use right, you would only get the 2 numbers you're trying to get rid of.
    0
     
    LVL 19

    Expert Comment

    by:peh803
    This is just an add on to mantarae's already great post, so please; give credit where credit is due (i.e., I'm NOT trying to steal anyone's points)!

    I just wrote a function (today!) to do this for me....Take a look, you may find it useful.

    Regards,
    peh803

    <%
    function trimRightChars(sStr, lNumChars)
      Dim sRetStr
      sRetStr = left(sStr, (len(sStr)-lNumChars))
      trimLastChar = sRetStr
    end function
    %>

    So, to trim off the right-most two characters, you'd do this:
    <%
    Dim sString
    sString = "1234567890"
    response.write "Untrimmed: " & sString & "<BR>"
    response.write "trim 1: " & trimRightChars(sString,1) & "<BR>"
    response.write "trim 2: " & trimRightChars(sString,2) & "<BR>"
    response.write "trim 3: " & trimRightChars(sString,3) & "<BR>"
    response.write "trim 4: " & trimRightChars(sString,4) & "<BR>"
    %>

    I think if you run this example, you'll see how it works!

    Regards,
    peh803
    0
     
    LVL 15

    Expert Comment

    by:Colosseo
    Hi

    i'm not trying to steal anyones points either :)

    but i think pehs function has a typo and should be

    <%
    function trimRightChars(sStr, lNumChars)
      Dim sRetStr
      sRetStr = left(sStr, (len(sStr)-lNumChars))
      trimRightChars= sRetStr
    end function
    %>

    Cheers

    Scott
    0
     
    LVL 19

    Expert Comment

    by:peh803
    yes scott, you're exactly right, thank you for that!

    peh803
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now