Skip to content

StringFormatting

Maxime ROUFFET edited this page Mar 12, 2023 · 4 revisions

String Formatting is a tool provided to directly paste arguments within a string using the defined SA::ToString (tries ToWString first) while logging.
The formatting is made by using %<index> to paste the argument at <index> at that place.

myFloat = 1.45f;
myBool = true;
SA::StringFormat("My string with %1 and %2, and finally %1 again!", myFloat, myBool);
"My string with 1.45f and true, and finally 1.45f again!"

Macros

String Formatting is automatically available within the log Macros for the _str and _details parameters.
Parenthesis ( ) must then be added to encapsulate the string and all the parameters to be formatted.

SA_LOG("Hello");                                                                     // No formatting.
SA_LOG(("My formatted string with %1 and %2!", myArg1, myArg2));                     // Format.
SA_LOG(("My formatted string with %1 and %2!", myArg1, myArg2), Normal, MyChannel);  // Additional parameters LogLevel and Channel must be outside of formatting ().
SA_LOG("Hello", Normal, MyChannel, ("My %1 formatted %1 details!", myArg1));         // Formatted details.

See example main.cpp for more examples.