Stringlist class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Created page with "The '''Stringlist''' class provides a facility that resembles an unbounded array of strings. While less generalized than a Collection class, it has a richer set of methods t...")
 
Line 24: Line 24:
Like all system classes, Stringlists are considered '''longstring-capable''', that is, any string inputs and outputs are considered longstrings for expression-compilation purposes.  The main impact of this is that Stringlist inputs and outputs will have standard longstring truncation behavior: truncation by assignment results in request cancellation.
Like all system classes, Stringlists are considered '''longstring-capable''', that is, any string inputs and outputs are considered longstrings for expression-compilation purposes.  The main impact of this is that Stringlist inputs and outputs will have standard longstring truncation behavior: truncation by assignment results in request cancellation.


In addition to the described methods, it is also possible to add data to a Stringlist with the [[HTML statement|HTML]] or [[Text statement]] using the '''To''' clause. This is especially useful if there is a block of mostly constant text to be added to a Stringlist.
In addition to the described methods, it is also possible to add data to a Stringlist with the [[Text and Html statements|HTML or Text statement]] using the '''To''' clause. This is especially useful if there is a block of mostly constant text to be added to a Stringlist.


  Begin
  Begin

Revision as of 16:15, 18 November 2010

The Stringlist class provides a facility that resembles an unbounded array of strings.

While less generalized than a Collection class, it has a richer set of methods than any Collection class. Unfortunately, the Stringlist class cannot be thought of as either a subset or superset of collections, so it is not necessarily an obvious decision as to which to use.

See Category:Stringlist methods for documentation on the Stringlist method API.

Stringlist usage

The Stringlist class is essentially an object-oriented version of $lists (described in the Sirius Functions Reference Manual). It is strongly recommended that all new applications use Stringlists instead of $lists:

  • Because they use the object-oriented model of instantiation, Stringlists eliminate the confusing behavior of $lists that results from their being tied to the statement that created them.
  • Stringlists are strongly datatyped, so application errors resulting from misuse of $list identifiers are eliminated. Code is clearer because it is obvious that a variable is a Stringlist -- $list identifiers are simply Float, Fixed, or String datatypes.
  • Because of the way $lists are instantiated, they are essentially unusable inside class methods.

Stringlist objects are instantiated with the New function or with methods that return Stringlist instances "under the covers" such as the [[SortNew {Stringlist method)|SortNew]] or [[Copy (Stringlist method}|Copy]] methods.

The system Discard method deletes a Stringlist object.

Stringlists are stored in CCATEMP, so they take minimal server table space no matter how large the Stringlist.

Like all system classes, Stringlists are considered longstring-capable, that is, any string inputs and outputs are considered longstrings for expression-compilation purposes. The main impact of this is that Stringlist inputs and outputs will have standard longstring truncation behavior: truncation by assignment results in request cancellation.

In addition to the described methods, it is also possible to add data to a Stringlist with the HTML or Text statement using the To clause. This is especially useful if there is a block of mostly constant text to be added to a Stringlist.

Begin
   %sl is object Stringlist
   %sl = New
   Text to %sl
   <html>
   <head>
   <title>Loading a complete web page into a stringlist</title>
   </head>
   <body>
   Each line of this text block is a new stringlist item.
   </body>
   End Text
   %sl:Print
End

Migrating from $lists to Stringlists

The MoveFromId and MoveToId methods facilitate migration from $lists to Stringlists: Stringlists can be passed to code that works on $lists after being converted to a $list with MoveToId; $lists can be converted to Stringlists with MoveFromId.

Compatibility

Before Sirius Mods Version 6.6, Stringlist items were limited to 6124 bytes in length.

In Sirius Mods Version 6.6, this limitation was lifted, and Stringlist items can be as many as 2**31-1 bytes long. While, as of Sirius Mods Version 6.6, all methods work correctly with Stringlist items longer than 6124 bytes, a few methods such as Locate and LocateUp still restrict their processing to the first 6124 bytes of a Stringlist item.