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

J

jain_tj

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
 
R

RobG

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).
 
D

Dr John Stockton

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 said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top