Lasso Soft Inc. > Home

[ staticarray->join ]

Method

The [staticarray->join] method may be used in three distinct ways. 

  1. To concatenate the elements of an array using the supplied parameter in between each element. Returns type string. Note: the parameter must be of type string or the method will error
  2. To append an element of any type to the array x times. Returns a new staticarray
  3. To add the elements of a second staticarray to the first . Returns a new staticarray. Note: The array to be added must be of type staticarray or the method will error.
  • Syntax
staticarray->join('string')

staticarray->join(number_of_copies, element)

staticarray->join( other_array )
Examples
  • Beginner

To join the elements of a staticarray into a string

Use the [staticarray->join] method with a supplied delemiter.

This example outputs a comma separated list of days of the week.

Code

var( daysOfWeek = staticarray( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') )
 
var (daysList = $daysOfWeek->join( ', ' ) )

$daysList+ '\n'
'daysList has type '+$daysList->type

Result

Sun, Mon, Tue, Wed, Thu, Fri, Sat
daysList has type string

To add elements to the end of a static array

Use the [staticarray->join] method with an integer value (number of copies) and the element you wish to add as parameters.

This example adds the element 'Sun' to the end of an array of days of the week 3 times.

Code

var( daysOfWeek = staticarray( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') )
 
var (daysList = $daysOfWeek->join(3, 'Sun') )

$daysList+ '\n'
'daysList has type '+$daysList->type

Result

staticarray(Sun, Mon, Tue, Wed, Thu, Fri, Sat, Sun, Sun, Sun)
daysList has type staticarray

To add the elements of another array to a staticarray

Use the [staticarray->join] method with a staticarray as the parameter.

This example ads the elements of an array of french days of the week to the end of an array of english days of the week

Code

var( daysOfWeek = staticarray( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'),
        joursDuSemaine =  staticarray( 'Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam') )
 
var (daysList = $daysOfWeek->join($joursDuSemaine))

$daysList+ '\n'
'daysList has type '+$daysList->type

Result

staticarray(Sun, Mon, Tue, Wed, Thu, Fri, Sat, Dim, Lun, Mar, Mer, Jeu, Ven, Sam)
daysList has type staticarray

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft