swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
Prerequisite Concepts      

String data type

The string data type is used to represent a string of characters.

You can declare a variable of type string:

  local string title
The default value for an uninitialized string shelf item is an empty string (that is, a string zero characters long). You can assign a value to a string in several ways:

You can define a function of type string and pass a string argument to a function:

  define string function greet
   value string recipient
   as 
     return "Hello " || recipient || "!"
  
  process
     output greet "Mars" || "%n"

The value of a string can be output, scanned, or used as the input to the markup parser. For instance,

  process
     local string s initial {"<a><b><c/></b></a>"}
     do xml-parse scan s
        output "%c"
     done

Strings and streams

The string data type replaces one of the functions of the stream data type. (Streams will continue to operate as strings when used as such, but this usage is deprecated.) However, string and stream are distinct types. A string and a stream can be used interchangeably in contexts in which they return the same type of value (a string), such as when they are output or passed to a value argument of a function, but you cannot perform stream-specific operation on a string:


  define function foo 
   read-only stream bar
   as
     output name of bar
  
  process
     local string baz
     foo baz

will compile correctly, but will lead to a run-time error because a string variable cannot be used with the name of operation.

Superseded functionality

The type stream has several roles in OmniMark, including the role of acting as a string variable. The role of string variable is now provided by the string type and the use of stream for this purpose is deprecated.

The type stream remains an important part of OmniMark and is still used for all cases where you need to attach a stream to a destination in order to stream data to that destination:

  process
     local stream out-file
     open out-file as file "out.txt"
     using output as out-file
        submit file #args[1] 

The use of stream in the following contexts is deprecated in favor of string:

Function arguments of type value stream:

  define function foo value stream my-stream

is deprecated in favor of value string:

  define function foo value string my-string

The use of stream as a return type for a function:

  define stream function foo

is deprecated in favor of string:

  define string function foo

The syntax remainder stream:

  define function foo (remainder stream s, ...)

is deprecated in favor of remainder string:

  define function foo (remainder string s, ...)

Prerequisite Concepts
 
   
 

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

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:35:14 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.