format

format -- generates a formatted string.

Syntax

format (format_string, arguments?...)

		

Arguments

format_string

A string containing format directives and literal text.

arguments

Expressions which will be matched to format directives on a one-to-one basis.

Returns

A string.

Description

Generates a formatted string using directives similar to those used in the "C" printf function. Text in the format_string will be output literally to the formatted string. Format directives consist of a percent sign (%) followed by one or more characters. The following directives are supported:

The format directive may contain control flags between the % sign and the format type character. These control flags are:

Format directives may contain field width specifiers which consist of an optional minimal field width as an integer, optionally followed by a period and a precision specified as an integer. The precision has different meanings depending on the type of the field.

Example

    Gamma> pi = 3.1415926535;
    3.1415926535000000541
    Gamma> format("PI is %6.3f",pi);
    "PI is  3.142"
    Gamma> alpha = "abcdefghijklmnopqrstuvwxyz";
    "abcdefghijklmnopqrstuvwxyz"
    Gamma> format("Alphabet starts: %.10s",alpha);
    "Alphabet starts: abcdefghij"
    Gamma> x = [1,2,3,4,5,6,7,8,9];
    [1 2 3 4 5 6 7 8 9]
    Gamma> format("x is: %a",x);
    "x is: [1 2 3 4 5 6 7 8 9]"
    Gamma> format("x is: %.6s",string(x));
    "x is: [1 2 3"
    Gamma> 
     

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.