swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
String data: formatting

OmniMark does not have a string data type, but you will encounter string-like data in many places in an OmniMark program:

You can output a string value directly. The following program outputs the value of a stream variable, the value of a literal string, the value of a pattern variable, another literal string, and a source:

  find letter+ => file-name
      local stream file-name initial {"The file"}
      output first-name
          || " named "
          || file-name
          || " contains%n"
          || file file-name

You can format string data using the "g" format command. By itself, the "g" format command does not change the original format of the string. However, you can use "g" in a format item to output the contents of a stream within a string expression:

  process
      local stream first-name initial {"John"}
      output "Hello %g(first-name)"

You can use the "l" and "u" format modifiers to force the string to lowercase or uppercase, respectively. The following program outputs "johnJOHN":

  process
      local stream first-name initial {"John"}
      output "Hello "
          || "lg" % first-name
          || "ug" % first-name

You can use the "f" format modifier to pad the string to a specified width. Spaces are added on the right to make up the width. If the string is longer than the specified width, the full string is output. The following program outputs [John ]:

  process
      local stream first-name initial {"John"}
      output "[" || "8fg" % first-name || "]"

You can use the "k" format modifier with the "f" modifier to pad the string to the left instead of the right: The following program outputs [ John]:

  process
      local stream first-name initial {"John"}
      output "[" || "8fkg" % first-name || "]"

You can use any reasonable combination of these modifiers together.

You can use the format command "g" in the format operator for any type of string expression. For instance:

  element "codeblock"
      output "lg" % attribute "language"

Format items, however, do not accept string expressions as arguments. You can use the "g" format command only with stream variables. To use a format item with a pattern variable, you must use the format command "x" in place of "g". All the same modifiers apply.

There are also format commands that can be used only in format items and are used to access and format various artifacts of markup parsing. These include, "c" (the parse continuation operator), "q" (which deals with element names), and "v" (which deals with attributes and external-data-entities).

       
----

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

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

Copyright © OmniMark Technologies Corporation, 1988-2000.