substring ?

F

find clausen

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

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

e

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('height=') +
7));
 
J

jon

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.indexOf("width=")!=-1) {
imgArray2 = imgArray1.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/
 
F

find clausen

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('height=') +
7));

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 ...
 
F

find clausen

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 ......
 
M

Mark Szlazak

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

find clausen

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 ... !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top