Skip to end of banner
Go to start of banner

arrayStructMap

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Availability

This routine is available starting with SIL Engine™ 4.8.0.11.

Syntax

arrayStructMap(structArray, field);

Package

array

Short Name

structMap (only when using package)

Description

Returns an indexed array of structs mapped to a given field name.

Parameters

Parameter name

Type

Required

Description

Struct ArrayArray of StructsYesAn array of structs to be indexed.
FieldStringYesName of the field to use as the indexer.

Return type

Struct []

Returns an array of indexed structs.

Example Part 1 - Data for structs

Assume we have a CSV file containing a list of toys. There is a column for the toy name and another for the toys color.

name, color
Airplane, White
Bouncy Ball, Blue
Car, Red
Dog, Brown
Elephant, Gray
...

Example Part 2 - Populating structs

With the given CSV data we can quickly populate an array of structs.

//define struct
struct _toy {
	string name;
	string color;
}

//create struct array and populate from csv
_toy [] toys = readFromCSVFile("toysList.csv", true);

Example Part 3 - Mapping the struct array

Now that we have a list of structs we can map them to one of the fields.

toys = arrayStructMap(toys, "name"); //mapping each array element to the name field

return toys["Bouncy Ball"].color; //element can be retrieved by name now that is has been mapped

Result: "Blue"

See also

  • No labels