Connecting Tech Pros Worldwide Help | Site Map

substring ?

  #1  
Old July 20th, 2005, 01:01 PM
find clausen
Guest
 
Posts: n/a

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

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


--

find clausen
www.photopress.dk
  #2  
Old July 20th, 2005, 01:01 PM
e
Guest
 
Posts: n/a

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...[color=blue]
>
> How do i find the value next to width= (500)
> in:
>
> '"../graphics/press/012.jpg" width=500 height=339'
>
>
> --
>
> find clausen
> www.photopress.dk[/color]


  #3  
Old July 20th, 2005, 01:01 PM
jon
Guest
 
Posts: n/a

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/
  #4  
Old July 20th, 2005, 01:02 PM
find clausen
Guest
 
Posts: n/a

re: substring ?


On Fri, 21 Nov 2003 11:33:12 -0800, "e" <e@e.com> wrote:
[color=blue]
> 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...[color=green]
> >
> > How do i find the value next to width= (500)
> > in:
> >
> > '"../graphics/press/012.jpg" width=500 height=339'[/color][/color]

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
  #5  
Old July 20th, 2005, 01:02 PM
find clausen
Guest
 
Posts: n/a

re: substring ?


On 21 Nov 2003 12:17:08 -0800, noreply@gurupika.com (jon) wrote:
[color=blue]
> 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[/color]

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

--

find clausen
www.photopress.dk
  #6  
Old July 20th, 2005, 01:03 PM
Mark Szlazak
Guest
 
Posts: n/a

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!
  #7  
Old July 20th, 2005, 01:04 PM
find clausen
Guest
 
Posts: n/a

re: substring ?


On 23 Nov 2003 00:10:46 GMT, Mark Szlazak <mszlazak@aol.com> wrote:
[color=blue]
> str = '"/graphics/press/012.jpg" width=500 height=339';
> value = (str.match(/width=(\d+)/))[1];
> alert(value);[/color]

he-he !

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

--

find clausen
www.photopress.dk
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
substring dyc answers 11 June 8th, 2007 11:18 AM
String manipulating using substring-before problem Jean-François Michaud answers 4 October 24th, 2006 06:05 PM
SUBSTRING for a regular expression btober@computer.org answers 5 November 23rd, 2005 01:24 AM
Bug: string.substring.trim = "" (boolean expression issue) Darren Anderson answers 11 November 21st, 2005 12:49 PM
substring function Radhika Sambamurti answers 7 July 22nd, 2005 07:45 AM