List2Array - Create an array from the elements in a delimited list

Top  Previous  Next

Syntax

 

<aList> := List2Array( <cList>, [<cSeparator>], [<lTrimElements>], [<aBrackets>] )

 

Parameters

 

<cList>

 

String containing a list of values.

 

<cSeparator>

 

Character to be used as separator when analyzing <cList>. Default is ",".

 

<lTrimElements>

 

Flag indicating if the elements should be AllTrimmed before they are put into the return array. If this parameter is .T. and a string containing only blank characters is passed as <cString>, an empty array ( {} ) is returned. If this parameter is .F. and a string containing only blank characters is passed, an array with one element (a string containing these blanks) is returned. The default for <lTrimElements> is .T. .

 

<aBrackets>

 

An array containing bracketing information in the form { { <openingBracket>, <closing Bracket> }, ... }. When a separator character is found between a pair of brackets it is not interpreted as a separator. Hence text between a pair of brackets is always kept together. Default is "no brackets".

 

Return value

 

An array containing the list elements in the string <cList>.

 

Description

 

List2Array analyzes the list <cList> passed to it as a string and returns the singled elements in an Array. The separator between the elements can be specified in <cSeparator>. Optionally every element can be trimmed from leading and trailing spaces. In case the separating character might be used in the elements, bracketing information can be passed. A separator character found between a pair of brackets is not interpreted as a separator.

 

Classification

 

Core

 

Category

 

Array and String Utility

 

Quick Info

 

Library: cckptcor.lib / cckptcor.dll

 

See also

 

Array2List

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

 

FUNCTION Main

 

LOCAL lst,arr

 

* Create a string list containing codeblock source code

lst := BlockList( { {|e|QOut(e),NIL} , {|e|QQOut(e),NIL} } )

 

* Show the list

? lst

 

* Make an array from that list. Don't interpret the commas in the codeblocks

* as separators

arr := List2Array(lst,",",.T.,{{ "{" , "}" }})

 

* Display the two codeblock sources

AEval(arr,{|elem|QOut(elem)})

 

RETURN NIL

 

 

* Convert an array of codeblocks into a string list of codeblock source

STATIC FUNCTION BlockList(p_arrayOfCodeBlocks)

 

LOCAL listOfCodeBlocks := ""

 

* Add the string representation of the passed codeblocks to a string list

AEval(p_arrayOfCodeBlocks,{|elem,no|listOfCodeBlocks += IIF(no>1,",","");

                                                     + Var2Char(elem)})

 

* return the string

RETURN listOfCodeBlocks