Xbasic

a5_parray_from_string Function

Syntax

dim result as n = a5_parray_from_string(C array_name, C format_string, C string, P vars)

Arguments

array_nameCharacter

Name of the array to create. Must be a valid Xbasic variable name.

format_stringCharacter

Defines how to map the data in the string to the property array. For more information about how to define the format, see <array>.initialize_properties().

stringCharacter

The data to populate the property array.

varsPointer

The namespace in which the array will be created. Pass in local_variables() to create the array at the local scope. See examples below.

Returns

resultNumeric

Returns the size of the array.

Description

Creates a property array from a CR-LF delimited string. Returns the size of the array.

Discussion

The a5_parray_from_string() function creates and populates a pointer array with data from a CR-LF delimited string. The format definition describes how the data in the string maps to properties in the array.

dim obj as p
dim format as c = "Name|Age:N|Position"
dim str as c = <<%string%
Stephanie|23|Sales
Joanne|45|Development
Rita|55|President
%string%


? a5_parray_from_string("people",format,str,obj)
= 3

? obj.people[2]
= Age = 45
Name = "Joanne"
Position = "Development"

To create the array in the local variable space, pass local_variables() as the fourth argument:

? a5_parray_from_string("people",format,str,local_variables())
= 3

? people
+[1].
+[2].
+[3].

? people[2]
= Age = 45
Name = "Joanne"
Position = "Development"

The a5_parray_from_string() function uses <array>.initialize_properties() to create the array. The above code could be written as follows using the <array>.initialize_properties() method:

dim format as c = "Name|Age:N|Position"
dim str as c = <<%string%
Stephanie|23|Sales
Joanne|45|Development
Rita|55|President
%string%


dim count as n 
count = line_count(str)
dim people[count] as p
people.initialize_properties(format,str)

See Also