string comparison in a loop

I have a countdown timer on a LCD touch screen. It shows a status message (string) and a number (int).

When the length of the string or int changes the old value stays. For example:

100
99

actually looks like
100
990

Because I didn't clear the pixels from the 0 at the end of 100 so it's still there.

I want to avoid clearing the screen every time because it'll make the screen flash a lot. I'd rather clear it selectively when the length changes, so when it goes from 3 digits to 2 (100 to 99) then clear. When the status message changes (one every 30-150 cycles) then clear the screen.

How would I copy the variable status_msg.name or status_msg.count and then compare it to itself next time through the loop to look for a change. Probably a simple question but I'm brain farting on how to do it.

void punchingStatusMsg( const boxing_start::PunchingStatus& status_msg)
{

myGLCD.setFont(BigFont);
myGLCD.print(status_msg.name, 100, 75);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(status_msg.count, 125, 130);

nh.spinOnce();

}

Try sending a space after the number. It will clear the next digit if there is one.

Can't add a space to the count since it's an integer.

char buffer[8];

snprintf(buffer, 7, "%d ", status_msg.count);
myGLCD.print(buffer, 125, 130);

Maybe there's an easier solution but you didn't post a link to the library you used.

Can't add a space to the count since it's an integer.

Printing a space after an integer, and adding a space to the count, are two very different things.

Print the int, then print a space.

pylon, I tried your code and it didn't fix it, the output was exactly the same.

For the graphic display I'm using UTFT.

I'm connecting a pair of 2560s to ROS (Robot Operating System) and am using a custom library that is generated based on message definitions defined in ROS. status_msg.name and .count are from that library.

For the string should I just concatenate a space on the end?

status_msg_name2 = status_msg.name + " ";

The trouble with printing a space is that I don't know where to print it. The space isn't needed in a fixed location, it'll change depending on the length of the string/int being printed.

I'm changing it on the ROS side to just use strings and put extra spaces in it. Seems like that's easier than trying to do it on the Arduino. Thanks for the help everyone.