04.04.2013, 11:19
Not sure how well known this is, only just figured this out for myself.
I wanted to limit the length of a string in a format, and usually I would have a separate string of the needed length, or use strmid, but I figured out that it can be done in format just like it can be done with floats.
This would show a float as a maximum of 4 decimal points.
You would think that this potentially the method to limit a string to 10 characters would be...
...but it's not, it's the same as the float...
... one thing that might be possible (haven't checked yet) is to use %5.10s to start at the 6th character in the string and take 10 characters from that point.
Sorry if this is old news.
I wanted to limit the length of a string in a format, and usually I would have a separate string of the needed length, or use strmid, but I figured out that it can be done in format just like it can be done with floats.
This would show a float as a maximum of 4 decimal points.
Код:
format(str, sizeof(str), "%0.4f", somefloat);
Код:
format(str, sizeof(str), "%10s", somestring);
Код:
format(str, sizeof(str), "%0.10s", somestring);
Sorry if this is old news.

