|
|
Subject:
number strings
Category: Computers > Programming Asked by: kitramos-ga List Price: $2.00 |
Posted:
01 Apr 2006 16:42 PST
Expires: 02 Apr 2006 23:46 PDT Question ID: 714445 |
okay I'm writing a javascript thing to display all the pictures I got. the thing works. I'm using an array to store the file names. the only thing that annoys me about this is how much of a task this turns to out be when adding a lot of new pictures. I found a program that will rename all the file names to numbers such as: 0001.jpg 0002.jpg 0003.jpg .... 0124.jpg and I figured well this will make things eaiser all I gotta do now is have it use the counter value and slap on a ".jpg" to the end to get the file name except that has it trying to look for 1.jpg 2.jpg 3.jpg ... 124.jpg and it of course doesn't find the picture, is there any way I could convice Javascript to use a set number of digets? |
|
There is no answer at this time. |
|
Subject:
Re: number strings
From: define_web-ga on 01 Apr 2006 17:26 PST |
this is some javascript code below, its a example to show you how to set-up the numbers. made a function that did what you want. and example just writes out the number to teh website, but you can edit it to do what you need. <script> function pad_zeroes (digits, n) { // n is a string or number if(n.constructor == Number) n = n.toString(); while(n.length < digits) n = "0" + n; return n; } var temp_number = ''; for (var i = 1; i < 124; i++) { // this is the number with zero padding temp_number = pad_zeroes(4, i) ; // just a test writes out the number on to the webpage document so you can see the number as it is made // only intrested in the 'temp_number' document.write(temp_number + '<br/>'); } </script> |
Subject:
Re: number strings
From: define_web-ga on 01 Apr 2006 17:33 PST |
<script > function pad_zeroes (digits, n) { // n is a string or number if(n.constructor == Number) n = n.toString(); while(n.length < digits) n = "0" + n; return n; } var full_numbers = ''; var temp_number = ''; for (var i = 1; i <= 124; i++) { // this is the number with zero padding temp_number = pad_zeroes(4, i) ; // string with all numbers as one for testing only full_numbers += temp_number + 'jpg, '; } // show alert msg for testing only alert(full_numbers); </script> |
Subject:
Re: number strings
From: frankcorrao-ga on 02 Apr 2006 09:25 PDT |
I don't know much javascript, but i did a quick check and it does seem that the string handling is a bit lame, so you probably do need a custom function like define_web has posted. Sad because something like C, that has lame string handling, can do this with just printf("%#.4d", <var>"); |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |