Overview

Array Slicing

Explores subset extraction and array management using the 'Copy' method. This example highlights how to efficiently slice dynamic arrays into smaller segments by specifying starting indices and counts.

Source Code

var alphabet: array of String = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
PrintLn('Full: ' + alphabet.Join(' '));

// Extract a range (slice)
// Note: Range syntax might vary, let's use the Copy function or manual loop if needed, 
// but DWScript supports slicing in some contexts. Let's check a standard way.
// Actually, DWScript supports array[start..end] syntax.

var slice := alphabet.Copy(1, 4); // Index 1, count 4
PrintLn('Slice (1, 4): ' + slice.Join(' '));

var fromStart := alphabet.Copy(0, 3); // Indices 0, 1, 2
PrintLn('Slice (0, 3): ' + fromStart.Join(' '));

var toEnd := alphabet.Copy(5, alphabet.Length - 5); // Indices 5 to end
PrintLn('Slice (5, end): ' + toEnd.Join(' '));

Result

Full: A B C D E F G
Slice (1, 4): B C D E
Slice (0, 3): A B C
Slice (5, end): F G
On this page