ListToItem (Stringlist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
mNo edit summary
Line 1: Line 1:
<span style="font-size:120%"><b>Convert Stringlist to single delimited Stringlist item</b></span>
{{Template:Stringlist:ListToItem subtitle}}


This method converts the contents of one Stringlist into a separator-delimited string which is overlayed on a single item of a second Stringlist.
This method converts the contents of one Stringlist into a separator-delimited string which is overlayed on a single item of a second Stringlist.
Line 5: Line 5:
ListToItem is a member of the [[Stringlist class]].
ListToItem is a member of the [[Stringlist class]].


==ListToItem Syntax==
==Syntax==
<pre>
{{Template:Stringlist:ListToItem syntax}}
%rc = %sl:ListToItem(strList2, itemnum, [separator])
===Syntax terms===
</pre>
 
===Syntax Terms===
<dl>
<dl>
<dt>%rc
<dt>%rc
Line 22: Line 19:
</dl>
</dl>


==Usage Notes==
==Usage notes==
<ul>
<ul>
<li>All errors in ListToItem result in request cancellation.
<li>All errors in ListToItem result in request cancellation.

Revision as of 19:48, 31 December 2010

Convert Stringlist to single delimited Stringlist item (Stringlist class)


This method converts the contents of one Stringlist into a separator-delimited string which is overlayed on a single item of a second Stringlist.

ListToItem is a member of the Stringlist class.

Syntax

%count = sl:ListToItem( strList2, itemNum, [separator])

Syntax terms

%rc
A numeric variable that is set to the number of Stringlist items overlayed on a single item in the output Stringlist (strList2), or it is set to a negative error code if an error has occurred.
%sl
A Stringlist object.
strList2
The Stringlist that contains the item to be overlayed by the delimiter-separated string generated from %sl, the method Stringlist.
itemnum
The number of the item from %strList2 to be overlayed by the delimiter-separated string generated from %sl, the method Stringlist. Each %sl item that does not appear in the delimiter-separated string becomes an item in the resultant Stringlist, %outlist.
separator
The delimiter character or characters to be used in the generated Stringlist item string. This optional argument defaults to comma (.,), and it can be the null string. Specifying separator as a null string is different from not specifying the argument at all, since in the latter case it defaults to a comma.

Usage notes

  • All errors in ListToItem result in request cancellation.
  • The target item in the output Stringlist is cleared to blanks before the overlay is done. If the target item is too short to hold the input Stringlist items, as many items and their trailing delimiters as will fit are placed in the target item, and the result of the ListToItem method is the number of items copied.
  • The delimiter-separated string generated by ListToItem can be longer than 255 bytes; its maximum is 6124 bytes.
  • Since no partial Stringlist items are placed into the target item, a good test for success of this method is a comparison of the result of ListToItem with a Count of the input Stringlist:
    if %list1:listToItem(%list2, %n) ne -
    %list1:count then
    ( error code )
    end if
    

    As an example of the use of this method, suppose Stringlist %list1 contained these three items:

    LLL
    MMMMM
    NN
    

    Suppose %list2 contained these two items:

    A,B,C,
    123456789012345678901234567890
    

    If this is the ListToItem invocation:

    %cnt = %list1:listToItem(%list2, 2)
    

    The resulting %list2 has two items, the second of which is blank-padded to 30 characters, and %cnt is set to 3.

    A,B,C,
    LLL,MMMMM,NN,
    

    Suppose Stringlist %list1 contains five items:

    EVERY
    GOOD
    BOY
    DOES
    FINE
    

    And Stringlist %list2 contains these three items, each padded to 22 characters:

    1234567890123456789012
    ***JUNK****
    THE,ITSY,BITSY,SPIDER,
    

    If this is the ListToItem invocation:

    %cnt = %list1:listToItem(%list2, 3, '++')
    

    The resulting %list2 has three items, each still padded to 22 characters, and %cnt is set to 3:

    1234567890123456789012
    ***JUNK****
    EVERY++GOOD++BOY++
    

    The third item, above, contains only three separated entries because there is insufficient space for the item "DOES" and the item delimiter characters.