Core Function Array Splicing

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
m (2 revisions)
 
(One intermediate revision by one user not shown)
Line 35: Line 35:
 
$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
 
$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
 
printr($Test[0..3]);
 
printr($Test[0..3]);
</syntaxhighlight>
 
 
Extract elements 0 to 3 from an array
 
<syntaxhighlight lang="sputnik">
 
$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
 
$Value = 0;
 
$AnotherValue = 3;
 
printr($Test[$Value to $AnotherValue]);
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 56: Line 48:
 
printr($Test[0..3, 5..6]);
 
printr($Test[0..3, 5..6]);
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
Extract elements 0 to 3 AND 5 to 6 AND 7 from an array
 
Extract elements 0 to 3 AND 5 to 6 AND 7 from an array

Latest revision as of 12:37, 14 June 2015

$newArray = $Array[ .. .. . . . . ]

Contents

Description

Copy parts out of an array and return them as a new array

Parameters

There is no limit.

Remarks

All actions apply to the array and only return VALUES not keys.

Splicing can overlap and return the same item more than once.

Spicing likes to use patterns such as:

'A'..'Z'
c65..c69
0..10
10..0
0x0A..0x65
$valuea to $valueb

If anything else is entered it will return the KEY that it links to.

Example

Extract elements 0 to 3 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3]);

Extract elements 3 to 0 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[3..0]);

Extract elements 0 to 3 AND 5 to 6 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3, 5..6]);

Extract elements 0 to 3 AND 5 to 6 AND 7 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3, 5..6, 7]);

Extract elements 0 to 3 AND 5 to 6 AND 7 to 1 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3, 5..6, 7..1]);

Extract a value out a dictionary (For whatever reason)

$Test = array(	"A" => "Zero",
				"B" => "One",
				"C" => "Two",
				"D" => "Three",
				"E" => "Four",
				"F" => "Five",
				"G" => "Six", 
				"H" => "Seven", 
				"I" => "Eight");
 
 
printr($Test['G']);

Extract a some of values out a dictionary

$Test = array(	"A" => "Zero",
				"B" => "One",
				"C" => "Two",
				"D" => "Three",
				"E" => "Four",
				"F" => "Five",
				"G" => "Six", 
				"H" => "Seven", 
				"I" => "Eight");
 
 
printr($Test['G'..'H']);

Extract a series of values out a dictionary

$Test = array(	"A" => "Zero",
				"B" => "One",
				"C" => "Two",
				"D" => "Three",
				"E" => "Four",
				"F" => "Five",
				"G" => "Six", 
				"H" => "Seven", 
				"I" => "Eight");
 
 
printr($Test['G'..'H', 'F'..'D', 'B']);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox