StringTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Miscellaneous Utilities : StringTools/FormatMessage

StringTools

  

FormatMessage

  

format a message string using %-interpolation

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

FormatMessage( fmt, param1, ..., param9 )

Parameters

fmt

-

string

param1, ..., param9

-

expressions

Description

• 

The FormatMessage procedure is used to interpolate %-specifiers in format strings. These are used in exceptions and warning messages throughout Maple.

• 

The FormatMessage(fmt, param1, param2, ...) function produces an output string from the format string fmt according to the following rule.

  

The string fmt is copied to the output and, whenever a '%' character followed by a decimal digit but not immediately preceded by another '%' character appears, it, and the adjacent digit, are replaced in the output by the result of converting the d-th parameter to a string. Here, d is the decimal value of the digit following the '%' character.

  

An exception to this rule is when the digit has the value d=0. In this case, all of the remaining parameters are copied to the output as a (comma,space)-separated sequence. If the '%' character is followed immediately by a '-' character, which is, in turn, followed immediately by a non-zero decimal digit with decimal value d, then the d-th parameter paramd is taken to be a small non-negative integer. The number is copied to the output as an ordinal of the same value.

• 

Up to nine parameters parami can appear after the format string fmt in the calling sequence.

• 

The FormatMessage procedure also supports automated pluralization. If, instead of a digit, a '%' character is followed by an expression in braces of the form %{d|<0 value>|<1 value>|<plural value>}, then the d-th parameter, which must be a non-negative integer, is replaced conditionally by whichever of the value tokens matches in number. Specifically, if the d-th parameter is 0, then the <0 value> string is interpolated; if the d-th parameter is 1, then the <1 value> string is interpolated; and, if the d-th parameter is an integer greater than 1, then the <plural value> string is interpolated.

• 

This function is part of the StringTools package, and so it can be used in the form FormatMessage(..) only after executing the command with(StringTools). However, it can always be accessed through the long form of the command by using the form StringTools[FormatMessage](..).

  

Note: For more sophisticated formatting capabilities, see sprintf.

Examples

withStringTools&colon;

FormatMessagefoo

foo

(1)

FormatMessagefoo&comma;bar&comma;2&comma;3

foo

(2)

FormatMessagefoo %1&comma;bar&comma;2&comma;3

foo bar

(3)

FormatMessagefoo %2&comma;bar&comma;2&comma;3

foo 2

(4)

FormatMessagefoo %3&comma;bar&comma;2&comma;3

foo 3

(5)

FormatMessagefoo %0&comma;bar&comma;2&comma;3

foo bar, 2, 3

(6)

FormatMessagefoo %-2&comma;bar&comma;2&comma;3

foo 2nd

(7)

FormatMessagefoo %-3&comma;bar&comma;2&comma;3

foo 3rd

(8)

FormatMessageThere %{1|are|is|are} %{1|no|one|many} thing%{1|s||s}.&comma;0

There are no things.

(9)

FormatMessageThere %{1|are|is|are} %{1|no|one|many} thing%{1|s||s}.&comma;1

There is one thing.

(10)

FormatMessageThere %{1|are|is|are} %{1|no|one|many} thing%{1|s||s}.&comma;5

There are many things.

(11)

FormatMessagefoo %-1&comma;N&comma;2&comma;3

foo N-th

(12)

fopen2

Error, invalid input: fopen expects its 1st argument, file, to be of type {string, symbol}, but received 2

FormatMessagelastexception2..1

invalid input: fopen expects its 1st argument, file, to be of type {string, symbol}, but received 2

(13)

lastexception

0&comma;invalid input: %1 expects its %-2 argument, %3, to be of type %4, but received %5&comma;fopen&comma;1&comma;file&comma;string&comma;symbol&comma;2

(14)

Compatibility

• 

The StringTools[FormatMessage] command was updated in Maple 15.

See Also

exceptions

fopen

lastexception

sprintf

string

StringTools

WARNING

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam