substring ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • find clausen

    substring ?


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

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


    --

    find clausen

  • e

    #2
    Re: substring ?

    var theString = '"../graphics/press/012.jpg" width=500 height=339';
    var theWidth = parseInt(theStr ing.substr(theS tring.indexOf(' width=') + 6));
    var theHeight = parseInt(theStr ing.substr(theS tring.indexOf(' height=') +
    7));

    <find clausen> wrote in message
    news:43urrv4kum h0d6h8p9efv7vjd m3a54vteb@4ax.c om...[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]


    Comment

    • jon

      #3
      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.len gth; 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



      Comment

      • find clausen

        #4
        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(theStr ing.substr(theS tring.indexOf(' width=') + 6));
        > var theHeight = parseInt(theStr ing.substr(theS tring.indexOf(' height=') +
        > 7));
        >
        > <find clausen> wrote in message
        > news:43urrv4kum h0d6h8p9efv7vjd m3a54vteb@4ax.c om...[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

        Comment

        • find clausen

          #5
          Re: substring ?

          On 21 Nov 2003 12:17:08 -0800, noreply@gurupik a.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

          Comment

          • Mark Szlazak

            #6
            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!

            Comment

            • find clausen

              #7
              Re: substring ?

              On 23 Nov 2003 00:10:46 GMT, Mark Szlazak <mszlazak@aol.c om> 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

              Comment

              Working...