Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Need to trim after a character

    Hello all. I have been searching for a while but can't find the answer i am looking for. What I need to do is trim all characters on the left of a '*' character, including the character. For example:

    Here is what I have...
    Code:
    D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL
    Here is what I need...
    Code:
    WW60-B05-SNL
    NOTE: Number of characters before the asterisk may not always be the same.

    Thanks,

    Parallon
    Last edited by parallon; 08-08-2007 at 11:24 PM. Reason: Added note about preceding character length.

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could try something like this:
    Code:
    strVar = "D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL"
    response.Write(MID(inStr(strVar,"*")+1,LEN(strVar))

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you for the quick response. I had to add a ')' to the end, although my test page is coming up blank. I see where you are going with this and I will look into it further tomorrow.

    Thanks again,

    Parallon

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    You are getting a blank page because the MID() statement is missing a required object.

    Here is what will produce the desired output:

    Code:
    <%
    strVar = "D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL"
    response.Write( MID(strVar,inStr(strVar,"*")+1,LEN(strVar)) )
    %>
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #5
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Assuming you want everything that comes after the last asterisk in the string, you could also do this:

    <%
    s = "D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL"
    a = split(s, "*")
    response.write(a(uBound(a)))
    %>

    Would that be any quicker to execute than calling lots of string functions? I've got a hunch it might but I've never actually tried.

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Hey Daemonspyre and Spudhead, both of those worked perfectly; thank you. Also, Mehere, thank you for the initial details.

    Parallon

  • #7
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    The only issue with Spud's (and, essentially both sets of codes) is that if you have 2 asterisks in the same string, you are not necessarily going to get the information you want.

    Just keep an eye out for it.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •