contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
Format items and the format operator
    Related Syntax  

Format items are used to insert characters that could not otherwise be used in a quoted string (such as double quotes), or to insert variable values into a quoted string. For example, the following action uses the "%"" format item to insert double quotes into a string:

  output "Richard said, %"Now is the winter of our discontent.%""

To insert the value of a stream variable into a quoted string, you use the "%g" format item, followed by the parenthesized variable name:

  process
     local stream animal initial {"lamb"}
     output "Mary had a little %g(animal)."

The value being inserted by the format item can often be changed by adding format modifiers to the format item. Format modifiers are usually single letters or digits that are inserted between the escape character and the letter of a format item. The "u" format modifier is used to output the value of a variable in uppercase letters:

  process
     local stream animal initial {"lamb"}
     output "Mary had a little %ug(animal)."

The output of this action would be "Mary had a little LAMB."

In addition to format items and format modifiers, OmniMark provides the format operator which allows you to dynamically format values in an OmniMark program. When using format items you have to use a using prefix in order to format shelf items other than the currently selected item. The format operator simplifies this procedure by allowing you to specify the shelf and item you want to format without having to use a using prefix.

For example, format items will insert the value of the currently selected item on a shelf into a string. To format values other than those of the currently selected item, you have to employ the using prefix:

  process
     local stream animal initial {"lamb","rat","platypus"}
     output "Mary had a little %g(animal).%n"
     using animal item 2
        output "Mary had a little %g(animal).%n"
     using animal item 1
        output "Mary had a little %g(animal).%n"

This process rule first outputs "Mary had a little platypus" because "platypus" is the currently selected item on the "animal" shelf. To output any other values from the shelf, the using prefix has to be used to specify which item you want to use. The format operator simplifies this process by allowing you to include the shelf item specification within the action in which it is used. Note that the "%" symbol is the short form for the format operator:

  process
     output "Mary had a little "
               || "g" % (animal item 2)

Format operators are an extension of the format items, and they use the same letters. For example, both the format item and format operator examples above use "g". You can use a format modifier with the format (%) operator the same way as you would use it with the format item:

  output "Mary had a little %ug(animal)"
  output "Mary had a little"
            || "ug" % (animal)

Additionally, the format (%) operator allows dynamic sizing of output values. For example:

  process
     local counter width
     local counter val
  ...
     set width to 4
  ...
     output ("d" % width || "d") % val

The format items that OmniMark provides are as follows:

      Related Syntax
   escape
   format
 
----

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:00:48 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.