PDA

View Full Version : Getting everything to the right of the 1st letter


mat
11-25-2002, 10:37 PM
Sorry for the lame subject line, couldn't think of anything else to sum it up.

Basically, I have a script and I know it will be sent a variable(or variables) and the variable names will start with 'Q' and then it will just be a few numbers, however the amount of numbers that come after this 'Q' could be 3,4,5 or 2 etc. and it will e different numbers each time. i.e

sending to script.. Q234 ...Q34 or even Q2

So I need to be able to make a variable called qauntity which will take everything to the right of the 'Q' so:

Q34 becomes quantity=34

&

Q894 becomes quantity=894


.. you get the idea. Can anyone offer a simple method for doing this. I have seen something like

quantity = Right(Item,6)

where 'item' is any variable sent to the script in this case 'Q345..'
The problem is that this has not worked for me, probably becuase you need to specify the exact number of character you'd like after the 'Q' and in my case that cannot be specified becuase it changes.

mat,

jeremywatco
11-25-2002, 11:01 PM
You can easily do all this with the split() function. Try this:

<%
formresult = Request.QueryString( "item" )

quantity = split(formresult, "Q")

Response.write(quantity(1))

%>

Save it as something like test.asp

and call it like this test.asp?item=Q4242 (whatever number)

it should display only the number and not the "Q"

mat
11-25-2002, 11:36 PM
yay! :D

rcreyes
11-26-2002, 05:47 AM
Another way to solve your problem is to use the MID() function, for example:

Variable1 = "Q12345"

Response.Write MID(Variable1, 2) '-- display 12345

Variable1 = "Y52"

Response.Write MID(Variable1, 2) '-- display 52

You no longer to hard-coded the beginning variable by using this method


Thanks,
Ray

mat
11-26-2002, 07:55 AM
:cool:

Thanks both.