Lists

 

A list is a string variable which itself contains one or more strings, each of which is delimited (separated) by a common character. For example, both FileItemize and WinItemize functions return a list of window names, delimited by tabs. In order to use functions which accept a list as a parameter, such as AskItemList, you will need to know what character is being used to delimit the list.

In order to support long file names, which can contain embedded spaces, the default file delimiter used to delimit lists of files and directories is a TAB.

To change the file delimiter to a character of your own choosing, use IntControl (29,p1,0,0,0).

Notes: Single item null lists ("") are not a valid list, therefore many of the following functions will have no affect. However, if you pass a null string to ItemInsert, it will insert a value.

Trailing delimiters are significant. This means that the comma-delimited list "a,b,c," has 4 items in it.

Functions that accept an 'index' allow you to specify -1 to represent the last item in the list.

If the function is passed a Unicode list then it will return a Unicode list.

 

Here are a few functions designed to deal with 'lists'.

ItemCount( list, delimiter )

Returns the number of items in a list.

ItemCountCsv( line, flags [, delimiter] )

Returns the number of items in a CSV line.

ItemExtract( index, list, delimiter )

Returns the selected item from a list.

ItemExtractCsv( index, line, flags [, delimiter] )

Returns the selected item from a CSV line.

ItemInsert( item, index, list, delimiter )

Adds an item to a list.

ItemLocate( item, list, delimiter )

Returns the position of an item in a list.

ItemLocateWild( pattern, list, delimiter, start )

Searches for an item in that list that fully matches a 'pattern'.

ItemRemove( index, list, delimiter )

Removes an item from a list.

ItemReplace( item, index, list, delimiter )

Replaces an item in a list.

ItemSort( list, delimiter )

Sorts a list.

 

You can parse a list using the following techniques:

 
; For Loop list = FileItemize( DirScript():"*" ) For index = 1 To ItemCount( list, @TAB )    strItem = ItemExtract( index, list, @TAB )    Message ("List Item",strItem) Next Exit
 
; ForEach Loop ; Converts a list to an array
list = FileItemize( DirScript():"*" ) ForEach strItem In ObjectType ("ARRAY", Arrayize (list, @TAB))    Message ("List Item",strItem) Next Exit
 
 

 

 

 

§         WIL Language Elements

§         Reference

§         Step by step guide to learning WIL

§         Notes