Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   substring ? (http://www.velocityreviews.com/forums/t874012-substring.html)

find clausen 11-21-2003 11:52 AM

substring ?
 

How do i find the value next to width= (500)
in:

'"../graphics/press/012.jpg" width=500 height=339'


--

find clausen
www.photopress.dk

e 11-21-2003 07:33 PM

Re: substring ?
 
var theString = '"../graphics/press/012.jpg" width=500 height=339';
var theWidth = parseInt(theString.substr(theString.indexOf('width =') + 6));
var theHeight = parseInt(theString.substr(theString.indexOf('heigh t=') +
7));

<find clausen> wrote in message
news:43urrv4kumh0d6h8p9efv7vjdm3a54vteb@4ax.com...
>
> How do i find the value next to width= (500)
> in:
>
> '"../graphics/press/012.jpg" width=500 height=339'
>
>
> --
>
> find clausen
> www.photopress.dk




jon 11-21-2003 08:17 PM

Re: substring ?
 
Hi,

Assuming that the number of digits in the width is not a certainty
(ie. could be 500 or 67 or 1005) then you can do it by splitting the
string on a space, looping the results to find the width, and
splitting the width on the equals sign. Just like this...

function getWidth() {
img = "../graphics/press/012.jpg' width=23 height=339";
imgArray1 = img.split(" ");
for (i=0; i<imgArray1.length; i++) {
if (imgArray1[i].indexOf("width=")!=-1) {
imgArray2 = imgArray1[i].split("=");
imgWidth = imgArray2[1];
alert(imgWidth);
}
}
}

btw - I flipped the quotes, but I think it can work either way.

best,

jon

http://www.gurupika.com/
http://forums.gurupika.com/

find clausen 11-22-2003 02:03 PM

Re: substring ?
 
On Fri, 21 Nov 2003 11:33:12 -0800, "e" <e@e.com> wrote:

> var theString = '"../graphics/press/012.jpg" width=500 height=339';
> var theWidth = parseInt(theString.substr(theString.indexOf('width =') + 6));
> var theHeight = parseInt(theString.substr(theString.indexOf('heigh t=') +
> 7));
>
> <find clausen> wrote in message
> news:43urrv4kumh0d6h8p9efv7vjdm3a54vteb@4ax.com...
> >
> > How do i find the value next to width= (500)
> > in:
> >
> > '"../graphics/press/012.jpg" width=500 height=339'


Thanx, in the mean time I found out to do it like this:

var str = photo[conv];
var pos=photo[conv].indexOf("=") + 1;
var wdt = str.substr(pos,3)

conv = a the number.

It is used to set the with of a text box below the picture in a
slideshow ...


--

find clausen
www.photopress.dk

find clausen 11-22-2003 02:06 PM

Re: substring ?
 
On 21 Nov 2003 12:17:08 -0800, noreply@gurupika.com (jon) wrote:

> Assuming that the number of digits in the width is not a certainty
> (ie. could be 500 or 67 or 1005) then you can do it by splitting the


It is always 3 . 300,400,500,350 ......

--

find clausen
www.photopress.dk

Mark Szlazak 11-23-2003 12:10 AM

Re: substring ?
 
str = '"/graphics/press/012.jpg" width=500 height=339';
value = (str.match(/width=(\d+)/))[1];
alert(value);


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

find clausen 11-23-2003 03:16 PM

Re: substring ?
 
On 23 Nov 2003 00:10:46 GMT, Mark Szlazak <mszlazak@aol.com> wrote:

> str = '"/graphics/press/012.jpg" width=500 height=339';
> value = (str.match(/width=(\d+)/))[1];
> alert(value);


he-he !

I like that, - allso love to compress codes ... !

--

find clausen
www.photopress.dk


All times are GMT. The time now is 04:55 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.