...

View Full Version : Need to trim after a character



parallon
08-09-2007, 12:18 AM
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...

D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL

Here is what I need...

WW60-B05-SNL

NOTE: Number of characters before the asterisk may not always be the same.

Thanks,

Parallon

mehere
08-09-2007, 12:27 AM
you could try something like this:

strVar = "D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL"
response.Write(MID(inStr(strVar,"*")+1,LEN(strVar))

parallon
08-09-2007, 12:42 AM
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

Daemonspyre
08-09-2007, 02:32 PM
You are getting a blank page because the MID() statement is missing a required object.

Here is what will produce the desired output:


<%
strVar = "D5BB1A96EEKE2FAGU8KFGEKMYHHL*WW60-B05-SNL"
response.Write( MID(strVar,inStr(strVar,"*")+1,LEN(strVar)) )
%>

Spudhead
08-09-2007, 03:20 PM
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.

parallon
08-09-2007, 04:26 PM
Hey Daemonspyre and Spudhead, both of those worked perfectly; thank you. Also, Mehere, thank you for the initial details.

Parallon

Daemonspyre
08-10-2007, 12:11 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum