If the number of rows and all values is fixed, so it looks like no problem.
Other way, you can make it a lookup table to can easily changes rows and values.
Or make it a "function" for improve the visibility of the part of code where it is inserted that "if".
OK thanks. I was hoping for some magic way of using a switch statement or some C trick I didn't know about that would speed up execution and reduce code space - the entire code compiles to 32722 bytes with this CPU maxing out at 32768. So very tight for space
I would have the limits and the strings in arrays and use a for loop to go through each case and assign the appropriate string to the string variable.
It is possible that you don’t need a string variable at all as these are inefficient but with only the small section of code you show it is hard to tell.
Regular C strings may seem daunting the first few times, but once you get used to them, your need for inefficient Strings will plummet. If you post the section of code where the String is used, we shall see if we can refactor it into regular C char arrays (or C strings, if you will).
Another way to shrink your code would be to compress your data in some way, for instance using bit fields, or compressing boolean flags into bytes and access them via bitmasks, and so on. Again, it's hard to tell if this can be done without looking at the whole picture.
If you really need all your code, still another solution is to get rid of the bootloader and directly flash the program via ISP. This can be done if you either have a programmer or another arduino board.
Thanks. I've already stripped the bootloader and using ICSP & can fit up to chip max of 32768. The string is next used to print to a TFT display using tft.print(sm) using similar to adafruit's GFX library.