swirl
Guide to OmniMark 7   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. This causes only one of that character to be output, even if two or more of the format items are output in succession. This is useful when building strings dynamically.

  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 ] [ LEGACYLIBRARIES ] [ ERRORS ]

OmniMark 7.1.2 Documentation Generated: June 28, 2005 at 5:44:36 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © Stilo Corporation, 1988-2005.