HomeAbout

SPrintf

ormatted strings are a real convenience—one that is sorely missing from the Flash Actionscript library. This adds in the sprintf functionality, which lets you reduce something like this:

Actionscript:
  1. var m,d;
  2. var myDate = new Date();
  3.  
  4. m = myDate.getMonth() + 1;
  5. if (m <10)
  6.     m = '0' + m;
  7.  
  8. d = myDate.getDate();
  9. if (d <10)
  10.     d = '0' + d;
  11.  
  12. trace(m + '-' + d + '-' + myDate.getFullYear());
  13. // traces out: 02-14-2004

into basically a single line of code:

Actionscript:
  1. var myDate = new Date();
  2. Sprintf.trace('%02d-%02d-%4d',myDate.getMonth() + 1, »
  3.     myDate.getDate(),myDate.getFullYear()));
  4. // traces out: 02-14-2004

http://natecook.com/downloads/sprintf.html

No Comments »

RSS feed for comments on this post. | TrackBack URI
You can also bookmark this on del.icio.us or check the cosmos

Leave a comment





XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .