String.format

Syntax

PP.String.format(string: String);

Parameters

string. Wildcard pattern, that contains parameters to insert: {0}, {1}, and so on.

Description

The format static method substitutes values to a string.

Comments

After the String parameter you can specify any number of wildcard characters or objects that look like {value: <value>, defaultFormat: <default format>}.

This method returns a String-type value.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Specify the source string, substitute values instead of its parameters and variables, and format the string after adding the desired carry-over:

// Set a string with parameters
sourceStr = "<script type=\"%Value1\" src=\"{0}\"></script>" +
    "<link type=\"%Value2\" rel=\"Stylesheet\" href=\"{1}\"></link>";
console.log("Source string:");
console.log(sourceStr);
// Substitute values instead of its parameters
var result = PP.String.format(sourceStr, "../build/PP.js", "../build/PP.css");
// Replace string variables with values
result = PP.String.pattern(result, {
    Value1: "text/javascript",
    Value2: "text/css"
}, True);
// Split the source string in two
result = PP.String.replaceAll(result, "><", ">\n<");
console.log("Formatted string with substituted values:")
console.log(result);

After executing the example the browser console displays the source string, and its new view that contains substituted values and required carry-overs:

Source string:

<script type="%Value1" src="{0}"></script><link type="%Value2" rel="Stylesheet" href="{1}"></link>

Formatted string that contains substituted values:

<script type="text/javascript" src="../build/PP.js">

</script>

<link type="text/css" rel="Stylesheet" href="../build/PP.css">

</link>

See also:

PP