Ahhhh silly me! it took me half a day the other day to figure out why i couldn’t get String.toInt() to work… then i realized “String” refers to the String variable name rather than typing String!
Thanks @jvanier ill set up another photon to test this… way too much awesome data coming in from my water monitor now my last shower was 70L at a rate of 15L/min hrmm time for a new water saving shower head i think!
There was a typo in the docs - now fixed. I’d really prefer to avoid the :: but not sure how to do that short of declaring a global instance that folks can use. E.g.
The easiest workaround might be to document a free function FormattedString(const char *format, ...) that calls the static String::format
Since format is static it’s actually has the surprising behavior right now that you can do String x; x.format("%d", 10"); but that doesn’t use x in any way. It doesn’t mutate x and assign it the formatted value. I’m not saying it should, but it’s puzzling.
Providing a free standing format function and not documenting the static String::format would solve both of these issues: how to create a new formatted string and avoid the surprise that calling format on an instance doesn’t mutate that instance.
Since format hasn’t been in the firmware for that long it should be OK to change it to an instance method. String().format(...) does look a little weird however…
From a memory management perspective, it makes a lot of sense because in many use cases you can create a global String then use format on it in the loop(). You don’t need to re-allocate the buffer if it’s big enough.
The other possibility is to make a varargs contructor to String (I’m not sure if that’s even possible) and ditch format altogether.