Create a formatted char*-string.

Create a formatted char*-string.

In plug-in versions prior 3.2 R2300 the output length (after all %-markers are replaced) is limited to 9999. Since 3.2 R2300 the limit is 32768. Longer strings may crash InDesign®.

Name Type Default Description
result char* - Result string. The string must be large enough to take up all replaced values.
formatStr char* - Message. The string can contain %-markes , see here to learn more. An additional parameter is expected in the (correct) sequence and with the correct type for each of these markers.
... depending on the %-markers - Values or variables according to the %-markers in formatStr

Assign "Hello 3rd World" to str in three different ways, then "Hello 4th Dimension"

int main()
{
    char	*	str	= alloc(512);
    char	*	w	= alloc(256);
    int			i	= 3;
strcpy(w, "World"); sprintf(str, "Hello 3rd World"); showmessage(str); sprintf(str, "Hello 3rd %s", w); showmessage(str); sprintf(str, "Hello %drd %s", i, w);
showmessage(str); strcpy(w, "dimension"); sprintf(str, "Hello %dth %s", ++i, w); showmessage(str);
release(str); release(w);
return 0; }

As showmessage also expects a format string, the % in the example have to be doubled

int main()
{
    char	*	str	= alloc(512);
    float		f	= 15.398735;
sprintf(str, "Der Preis steigt um %.2f%%%%, also ungefähr %.0f%%%%", f, f); showmessage(str);
release(str);
return 0; }

Since

Available
priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

Alphabetic index HTML hierarchy of classes or Java