Reputation: 95
I am using the new method: Utilities.formatString()
In the Google Documentation is says it is similar to sprintf %-style.
I searched and read this article about sprintf in PHP.
I cannot seem to get this to work as intended. It is meant to pad this 8 character string with 4 leading zeros. I know there are other ways to do this, But I am trying to get a handle on this sprintf / formatString thing.
var noFormat = "12345678";
var formatted = Utilities.formatString("%012s", noFormat);
I expected the var formatted to be equal to "000012345678". my debugger tell me that formatted = 0, or sometimes it throws an error..
I am confused.
Upvotes: 7
Views: 23183
Reputation: 46802
try it like this :
function xxx(){
var noFormat = '12345678'
var formatted = Utilities.formatString("%012d", noFormat);
Logger.log(formatted)
}
the different parameters that can be used are easy to find on the web, here is an example that explains how the argument must be evaluated in php but the usage is the same.
Logger result :
Upvotes: 10