hey
i am using regexp to inject commas into my years by searching for 000
and replacing with ,000 like this
var pattern:RegExp = /000/;
sYear = sYear.replace(pattern, ",000");
however, this approach will bug every multiple of 10,000 as there are
more zeros than the pattern expects.
is there a way of counting back from the end of the number and
inserting the comma (even without a regular expression)? if i use the
g modifier in the regexp (so var pattern:RegExp = /000/g;), it will
only pick up the first 000 (and every multiple thereafter) instead of
leaving the first 0 (which is expected behaviour but something i'd
like to get around)
would you use an if statement to count the length of the sYear string
or is there a better way?
at the moment, because i know that i only need years from 15,000 bc,
i'm doing this:
var sYear:String = String(nYear);
if (sYear.length > 5)
{
if (sYear != "-10000")
{
var pattern:RegExp = /000/;
sYear = sYear.replace(pattern, ",000");
} else {
var pattern:RegExp = /0000/;
sYear = sYear.replace(pattern, "0,000");
}
}
which is a bit hacky and limited
interested to hear your answer
a
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders