Functions Index :: S :: StrPrint
StrPrint(string format, val "p01", val "p02", val "p03", val "p04", ..., val "p50")
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).
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:
- %b: interpret variable as a bool (replace with "true" or "false").
- %c: interpret variable as a clip; replace with its framecount.
- %f: interpret variable as a float (replace with its value, stripping trailing zeros with ZStrip()).
- %g: interpret variable as a clip; store it as an auto-global and replace with the auto-global's name .
- %i: interpret variable as an integer.
- %q: interpret variable as a string; quote it with double quotes before replacing.
- %s: interpret variable as a string.
- %v: interpret variable as having any possible type and replace appropriately after determining it. Clips are treated as if %c was specified.
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):
- %%: Replace with a % character.
- \n: Replace with a line feed character.
- \r: Replace with a carriage return character.
- \t: Replace with a tab character.
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.
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)
: %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.