PStrings are extremely lightweight string objects that derive from Print. They are designed to render values into character buffers using the same familiar syntax that Serial and LiquidCrystal etc. provide:
str.print("The temperature is "); str.print(temp); str.println(" degrees."); // do something with str here
PStrings do not own buffers, but instead manage predefined ones. To create a PString, you pass an existing buffer and its size to the constructor:
char buf; PString str(buf, sizeof(buf));
[u]On-the-fly rendering[/u] If, like many users, you just need a quick-and-dirty way to convert some value to a string, you can use PString's constructors to do it inline. The following examples look like simple function calls, but actually create temporary objects which perform the requested rendering before vanishing:
#define PI 3.14 int voltage = 255; char buf; PString(buf, 40, PI); Serial.print(buf); // prints 3.14 PString(buf, 40, voltage); Serial.print(buf); // prints 255 PString(buf, 40, voltage, HEX); // buf now contains "FF" Serial.print(buf); // prints FF
I posted PString to the playground and also here. Thoughts and suggestions for improvements are welcome.