Functions Index :: S :: StrPrint

[<< up one level]

Module:

string :: sprintf

Definition:

StrPrint(string format, val "p01", val "p02", val "p03", val "p04", ..., val "p50")

Description:

An sprintf-like string formatting function.

It permits incorporation of string representations of up to 50 variables into a pre-built expression (the format string).

It also allows the incorporation of format characters (tabs, linebreaks, etc.).

Very useful for creating subtitles, log entries and function calls or other code strings to be passed to the Eval() standard avisynth function or other Avisynth, plugin or user functions (for example: to build RPN expressions for the xxxLut functions of MaskTools).

Arguments:

format: String containing variable substitution placeholders which will be replaced by an appropriate string representation of the corresponding variable's value (in all cases except %q as a string without double quotes). The substitution placeholders have the form:

Total number of variables (and thus substitution placeholders) accepted is 50.

In addition, the following formating placeholders have a special meaning (and may be present in any number):

p01, p02, ..., p50 (Optional): The variables that will supply values for replacing the substitution placeholders of the format string. "

Notes and conditions on arguments relations:

1] All substitution and formatting placeholders' strings are case sensitive.

2] The number of variables must correspond exactly to the number of substitution placeholders contained in the format string else the function will throw an error.

3] If some of the variables supplied to the function are not defined, they will be treated as non-existent; this is a feature but it means that you must be careful because substitution of placeholders in the format string is performed with the order that defined arguments are supplied to the function.

4]You can use the function to perform only formatting substitutions if no variables are supplied and the format string contains only formatting placeholders.

Examples:

fmt = "Current source is a %ix%i %f fps %s clip ."

c = AVISource(…)

ct = c.IsRGB ? ""RGB"" : (c.IsYUY2 ? ""YUY2"" : ""YV12"")

rst = StrPrint(fmt, c.Width, c.Height, c.Framerate, ct)

return BlankClip().Subtitle(rst)

 

[<< top]

 


[1]: %g is useful for creating parameter strings to be passed at array operator functions, in order to convert a local clip variable to a global variable. The mechanism used to do so is the same as the one used for the implementation of AVSLib's array type.