Hi
I am wondering if there is a more effective way of parsing a format string and replacing parts of the string with values. For example
"T: $H:$M:$S" should be replaced by hours, minutes seconds. But the string should be variable, it could only be $S or $M:$s or $H:$M .... (lowercase means no leading zero).
I tried to use Lang.format, but it doesn't really make it easier to replace the $M with $1$ etc, because the order is not fixed.
The way I am currently doing it, is going through the whole string and searching for the strings to replace (1 by 1).
var sec = Math.floor(val).toNumber(); var min = Math.floor(sec.toFloat()/60.0).toNumber(); var hr = Math.floor(min.toFloat()/60.0).toNumber(); sec = sec%60; for(var i = 0; i < fmttext.length(); i++) { var part = fmttext.substring(i, i+2); ... if(part.equals("$H") || part.equals("$h")) { newtext += hr.format("%" + (part.equals("$H") ? "02" : "") + "d").toString(); i++; } else { newtext += fmttext.substring(i, i+1); } ... }
The string.format function does not take any other characters as the one to replace, so that would make it much easier.
Thanks for any help!
regards
Erich