...

View Full Version : could someone teach me how to modify a string



gerble1000
10-02-2012, 05:36 PM
i have a variable that looks like this
9/thumb1.png?=38255

the first number could range from 1 to 33
could someone explain how to get the first value before the forward slash into a variable.
so in this case it would be '9'
but could be ''33'

WolfShade
10-02-2012, 05:45 PM
Google "javascript split". Split the value using / as the delimiter. The first position (position 0, not 1) will be the number you are seeking.

durangod
10-02-2012, 05:46 PM
does it have to be using js, you can do it with php really easy using explode here is the link http://php.net/manual/en/function.explode.php

im not sure really how to do this with js either but you might want to check out regex stuff i think thats what you want to use.

http://www.regular-expressions.info/



UPDATE: cool wolfshade i learned something today already, nice

DanInMa
10-02-2012, 05:49 PM
here's a simple example


function myFunc(string) {
var a = []
a= string.split('/')
alert(a[0])
}

gerble1000
10-02-2012, 06:03 PM
cheers guys just downloaded a pdf on it.
and the example worked great



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum