Algosim documentation: format

format

Creates a string containing object values using a template.

Syntax

Description

The format function creates a string containing object values using a template string with placeholders.

The result will equal s except that every occurrence of the substring "%1" will be replaced by x[1], every occurrence of "%2" by x[2]. Valid placeholders are %1 to %9, but each placeholder can occur any number of times in s. If a given placeholder %k occurs (k = 1..9) in s, then x[k] must exist; otherwise an error is raised. On the other hand, it is not necessary that every element of x is referenced in s.

To put an actual percent sign in the result, write %% in s. In s, any percent sign must be followed by a positive digit or another percent sign, except for these second percent signs in %%.

Examples

n ≔ 1000; MessageBox(format("There are %2 primes less than or equal to %1.", '(n, PrimePi(n))))

Image 1