Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Need to output "String id" as "Numeric value" in different places using a loop

Reply
Thread Tools

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

 
 
jain_tj@rediffmail.com
Guest
Posts: n/a
 
      03-31-2006
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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      03-31-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      04-01-2006
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 <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Count bits in VHDL, with loop and unrolled loop produces different results a s VHDL 16 03-08-2011 05:35 PM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
How can I network my pc to my brothers pc and we live in different places, TIA Joseph Minelli Computer Support 19 09-21-2003 07:41 AM
possible to create a control that adds portions of itself different places? Christian H ASP .Net 0 08-08-2003 10:53 AM



Advertisments