Name: Anonymous 2012-02-08 13:42
www.d-programming-language.org/
Hey /prog/! Today we're going to learn about the D programming language. Today's topic is array slices.
Array slices in D capture a [bold]view[/bold] of the original array. They DO NOT create a copy.
In D, since strings are arrays of characters, the exact same syntax works with strings.
So as you can see, modifying a slice of an array also modifies the original array. Good luck coding!
Hey /prog/! Today we're going to learn about the D programming language. Today's topic is array slices.
// main.d
void main() // Ok in D. The runtime handles main's return
{
int[10] arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
int[2] slice = arr[3..5];
writeln(slice) // "[4, 5]"
}Array slices in D capture a [bold]view[/bold] of the original array. They DO NOT create a copy.
In D, since strings are arrays of characters, the exact same syntax works with strings.
// main.d
int main() // int main() is fine as well
{ // but you must supply a return value
string s = "Yo prog, I herd you liek programming";
// $ is shorthand for the end index of the array
string sslice = s[10..$];
writeln(sslice); // "I herd you liek programming";
sslice = "I herd you liek jews";
writeln(sslice); // "I herd you liek jews"
writeln(s); // "Yo prog, I herd you liek jews"
return 0;
}So as you can see, modifying a slice of an array also modifies the original array. Good luck coding!