CreateLines (Stringlist function): Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (1 revision) |
(No difference)
|
Revision as of 13:46, 16 January 2011
Create delimited string from Stringlist (Stringlist class)
This method is used to create a delimited string from a Stringlist object. Generally, as the name of the method suggests, the string would be created with line-end character delimited lines. The CreateLines method accepts one positional argument and one name required argument, and it returns a string result.
CreateLines is a member of the Stringlist class.
Syntax
%string = sl:CreateLines[( [delim], [AddTrailingDelimiter= boolean])]
Syntax terms
- %string
- This longstring is to contain the data in %sl.
- %sl
- A Stringlist object.
- delim
- The delimiter string to be used between Stringlist items in the output string. This is an optional argument. If this argument is not specified, the delimiter used is X'25', which is an EBCDIC line-feed. If this argument is a null string, the Stringlist items are concatenated.
- AddTrailingDelimiter= boolean
- The name required argument .AddTrailingDelimiter is a boolean value that indicates whether a trailing delimiter should be added to the output string. This optional argument defaults to .true, which results in a trailing delimiter being added to the output string.
Usage notes
- All errors in CreateLines result in request cancellation.
- The CreateLines method is available in Sirius Mods Version 6.7 and later.
Examples
- The following loads a Stringlist with the names of the four greatest stooges and then places them into a string, separated by plus signs:
%list is object stringList %stooges is longstring %list = new text to %list Curly Larry Moe Shemp end text %stooges = %list:createLines('+')
After the CreateLines method, .%stooges contains the following:
Curly+Larry+Moe+Shemp+
- In the following example, the contents of Stringlist .%sendData are sent over a Janus Sockets connection (using a Socket object) as line-feed delimited lines:
%sock is object socket %sendData is object stringList ... %sock:send( %senddata:createLines($x2c('25')) )
In this example, the delimiter parameter (.$x2c('25')) was really unnecessary because it's the default. In this example, one would presume that the socket is in.CHAR mode, that is, data is being translated from EBCDIC to ASCII. Obviously, the CreateLines method does nothing that you could not do quite easily in User Language. It is just a little more convenient and efficient. - The default behavior of CreateLines is to add a trailing delimiter. This default is based on the fact that most ASCII applications end the last line of a file with the line-end character(s), so they expect other applications to do the same. Still, the default can produce somewhat undesirable behavior, especially in interactions with ParseLines (Stringlist subroutine).
In the following example, a string is created without a trailing line delimiter:
%sendString = %senddata:createLines($x2c('25'), addTrailingDelimiter=false)