substring ?

Discussion in 'Javascript' started by find clausen, Nov 21, 2003.

  1. find clausen

    find clausen Guest

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

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


    --

    find clausen
    www.photopress.dk
    find clausen, Nov 21, 2003
    #1
    1. Advertising

  2. find clausen

    e Guest

    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));

    <find clausen> wrote in message
    news:...
    >
    > 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, Nov 21, 2003
    #2
    1. Advertising

  3. find clausen

    jon Guest

    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/
    jon, Nov 21, 2003
    #3
  4. find clausen

    find clausen Guest

    On Fri, 21 Nov 2003 11:33:12 -0800, "e" <> 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('height=') +
    > 7));
    >
    > <find clausen> wrote in message
    > news:...
    > >
    > > 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, Nov 22, 2003
    #4
  5. find clausen

    find clausen Guest

    On 21 Nov 2003 12:17:08 -0800, (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
    find clausen, Nov 22, 2003
    #5
  6. find clausen

    Mark Szlazak Guest

    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!
    Mark Szlazak, Nov 23, 2003
    #6
  7. find clausen

    find clausen Guest

    On 23 Nov 2003 00:10:46 GMT, Mark Szlazak <> 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
    find clausen, Nov 23, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9u?=

    web sddress substring

    =?Utf-8?B?Sm9u?=, Nov 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    366
    Karl Seguin
    Nov 30, 2004
  2. juli
    Replies:
    3
    Views:
    8,848
    Shiva
    Dec 6, 2004
  3. Badass Scotsman

    Finding a SubString within a String

    Badass Scotsman, Mar 31, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    6,110
    S. Justin Gengo
    Mar 31, 2006
  4. Sean
    Replies:
    0
    Views:
    331
  5. Replies:
    3
    Views:
    189
    Sherm Pendley
    Aug 3, 2005
Loading...

Share This Page