swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
    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:

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

The syntax of a dynamic format item is:

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
  include "ombcd.xin"
  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 ] [ OMX ] [ OMX ] [ ERRORS ]

Generated: August 11, 2000 at 3:06:21 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.