PDA

View Full Version : basic string manipulation question


patrik
05-02-2003, 06:48 PM
Ok, I give - what's the simple way to remove the first character in the contents of a variable?

I'm appending variables to a link in order to pass it to the next page*, and SLICE-ing it as below, which does work:

myString = new String(location.search) ;
mySlice = myString.slice(1) ;

Is there a simpler way to remove the "?" that comes in as the first character of location.search?

TIA!

*please tell me this work cross-domain!

cheesebagpipe
05-02-2003, 06:52 PM
location.search already is a string.

mySlice = location.search.substring(1);

beetle
05-02-2003, 06:57 PM
other ways, just for the heck of it

mySlice = location.search.replace( /^\?/, "" );

mySlice = location.search.slice( 1 );

patrik
05-02-2003, 07:08 PM
Bless you, kind sirs - those are exactly what I was looking for!

(I love this place...)