My instinct is to insert a serial newline (\n) character at the appropriate places in the string.
If wrap means word-wrap, then that sounds reasonable.
Is there a similar search and replace routine in arduino, or is there an easier way to wrap strings?
That depends on whether you are talking about strings (NULL terminated array of chars) or Strings (instances of the String class), and what you mean by "the end of the row".
I saw nothing in your post that defined either of these items.
When I say “the end of the row” I meant the end of the line, the length of which is defined by the variable cols in the ruby code.
You won't be able to do this directly:
printer.println(“Message here...”);
You could create a function:
void printWrapped(char *msg, int cols)
{
}
and call it:
printWrapped(“Message here...”, 30);
In the function, get the length of the string. If it is less than 30, nothing needs to be done to the string before calling printer.print().
If it is more than 30, use a for loop, starting at 29 counting down. If you find a space, record the position, then print the part of the line up to that position, by changing the space to a NULL.
If there are no spaces, you'll need to copy the character in position 29, replace it with a NULL, and print the string.
Then, replace the NULL with the original character, shuffle the array to the left by the number of characters printed, and repeat the process (using a while loop).