Core Function Join

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Return Value)
(Example)
Line 32: Line 32:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$days = Split("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")
+
$days = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
For $day In $days
+
Foreach $day ($days)
println("Element is: " . $day)
+
{
Next
+
println("Element is: " . $day);
println("Back together is " . join($days, ":")   )
+
}
 +
println("Joined together is " . join($days, ":") );
 +
// Prints: Joined together is Sun:Mon:Tue:Wed:Thu:Fri:Sat
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Heres another way of writing it
 
 
<syntaxhighlight lang="sputnik">
 
$days = Split("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")
 
For $day In $days
 
println("Element is: " . $day)
 
Next
 
println("Back together is " . $days::join(":")  )
 
</syntaxhighlight>
 
 
Note the :: this will allow a function to be called using the variable its attached to becomes the first param.
 
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 21:52, 16 November 2011

Join( <array>, <separator> )

Contents

Description

Join an array into a string with an optional separator.

Parameters

array

The array to join.

separator

Optional; A string to place between each array element.

Default is " " a space.

Return Value

Success - The array merged into a string.

Failure - Returns an empty string.

Remarks

This does not alter the original array.

Example

$days = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
Foreach $day ($days)
{
	println("Element is: " . $day);
}
println("Joined together is " . join($days, ":") );
// Prints: Joined together is Sun:Mon:Tue:Wed:Thu:Fri:Sat
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox