swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
    Related Syntax  

Format items

Format items are a means of inserting data into a literal string. They have a wide variety of uses:

Format items can be divided into two classes based on their syntax:

Static format items

The syntax of a static format item is as follows:

Format strings consist of zero or more format modifiers followed by a format command.

Static format items are

The format items that represent white space ("t", "n", "_") can take an "s" format modifier, which indicates that white-space stripping can be applied to the character.

  process
      output "First line%sn"
      output "%snSecond line %sn"

Dynamic format items

Dynamic format items are generally used with the format operator, as in:

Note that format items do not accept expressions or literal strings. To format the result of an expression, use the format item in quotes, the % operator, followed by the expression or quoted string.

Literal string example:

  ; pad-quote-string.xom
  ; "8fg" pads the quoted string "foo" with spaces to a width of 8
  process
      output   "8fg" % "foo"  || "END"
  ; Output: "foo     END"

Two kinds of format strings are supported, format instructions and templates. A format instruction consists of a format command preceded by one or more format modifiers. A template consists of "<", a set of template characters, and ">".

The example format.xom uses format instructions:

  ;  format.xom
  import "ombcd.xmd" unprefixed
  process
     local bcd foo initial {233.33}
     local stream bar initial {"'Twas brillig and the slithy toves"}
     output "Foo padded to right to 8 digits: [" || "8fd" % foo  || "]%n"
     output "Bar uppercased: " || "ug" % bar || "%n"
  ; Output:  Foo padded to right to 8 digits: [233.33  ]
  ;            Bar uppercased: 'TWAS BRILLIG AND THE SLITHY TOVES

In format.xom, we have two format instructions:

At the end of the line containing each of the two format instructions, there is also a static format item, "%n", to insert a newline character.

The format string varies according to the type of the variable.

To format the values of specific data types using dynamic format items, see:

The format commands used in dynamic format items, and the types they are used with, are:

    Related Syntax
   escape
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 8.2.0 Documentation Generated: March 13, 2008 at 3:25:49 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2008.