Need to output "String id" as "Numeric value" in different places using a loop

Discussion in 'Javascript' started by jain_tj@rediffmail.com, Mar 31, 2006.

  1. Guest

    Could anyone please help me with the following problem

    My xml file is
    ==============
    <fig id="F0000001">
    <caption>Caption text</caption>
    <image id="I0000001" image.class="halftone" image.type="jpg" print="0"
    width="29-6" depth="23-6" pointer="I0000001.jpg"/>
    </fig>

    I need my output in IE Browser using Javascript as follows (need it in
    a loop, as I need to print in different places)

    fig id output
    ======== ========
    F0000001 1
    F0000021 21
    S0000001 1
    S0000021 21
     
    , Mar 31, 2006
    #1
    1. Advertising

  2. RobG Guest

    Re: Need to output "String id" as "Numeric value" in different placesusing a loop

    wrote:
    > Could anyone please help me with the following problem
    >
    > My xml file is
    > ==============
    > <fig id="F0000001">
    > <caption>Caption text</caption>
    > <image id="I0000001" image.class="halftone" image.type="jpg" print="0"
    > width="29-6" depth="23-6" pointer="I0000001.jpg"/>
    > </fig>
    >
    > I need my output in IE Browser using Javascript as follows (need it in
    > a loop, as I need to print in different places)
    >
    > fig id output
    > ======== ========
    > F0000001 1
    > F0000021 21
    > S0000001 1
    > S0000021 21


    To converting the string a primitive number assuming the format above:

    var stringID = 'I00301';
    var numberID = stringID.replace(/^\D*0*/,''); // --> 301


    That will remove any leading non-digits and zeros in any browser that
    supports regular expressions (which includes IE).



    --
    Rob
     
    RobG, Mar 31, 2006
    #2
    1. Advertising

  3. Need to output "String id" as "Numeric value" in different places using a loop

    JRS: In article <442d2c51$0$2142$5a62ac22@per-qv1-newsreader-
    01.iinet.net.au>, dated Fri, 31 Mar 2006 23:17:55 remote, seen in
    news:comp.lang.javascript, RobG <> posted :

    >To converting the string a primitive number assuming the format above:
    >
    > var stringID = 'I00301';
    > var numberID = stringID.replace(/^\D*0*/,''); // --> 301
    >
    >
    >That will remove any leading non-digits and zeros in any browser that
    >supports regular expressions (which includes IE).


    And will remove the whole of "F0000000".
    Maybe stringID.replace(/^\D*0*(.)/, '$1'); to be safer?

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Apr 1, 2006
    #3
    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. Christian H
    Replies:
    0
    Views:
    295
    Christian H
    Aug 8, 2003
  2. Replies:
    5
    Views:
    948
    X-Centric
    Jun 30, 2005
  3. Adotek
    Replies:
    3
    Views:
    626
    Bob Barrows [MVP]
    Apr 3, 2007
  4. Isaac Won
    Replies:
    9
    Views:
    390
    Ulrich Eckhardt
    Mar 4, 2013
  5. Tim Roberts
    Replies:
    0
    Views:
    49
    Tim Roberts
    May 20, 2014
Loading...

Share This Page