By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,070 Members | 1,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,070 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ja*****@rediffmail.com 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
Mar 31 '06 #2

P: n/a
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 <rg***@iinet.net.au> 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.
Apr 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.