Connecting Tech Pros Worldwide Help | Site Map

substring ?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 12:01 PM
find clausen
Guest
 
Posts: n/a
Default 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

  #2  
Old July 20th, 2005, 12:01 PM
e
Guest
 
Posts: n/a
Default 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, 12:01 PM
jon
Guest
 
Posts: n/a
Default 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, 12:02 PM
find clausen
Guest
 
Posts: n/a
Default 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, 12:02 PM
find clausen
Guest
 
Posts: n/a
Default 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, 12:03 PM
Mark Szlazak
Guest
 
Posts: n/a
Default 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, 12:04 PM
find clausen
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.