Substring: Difference between revisions

Content added Content deleted
(Undo revision 109590 by Markhobley The change asks for a lot of tasks to be updated without flagging such, or mentioning it on the talk page.)
(Updated D code)
Line 411: Line 411:
{{works with|D|2}}
{{works with|D|2}}
<lang d>import std.stdio, std.string;
<lang d>import std.stdio, std.string;

void main() {
void main() {
string str = "the quick brown fox jumps over the lazy dog";
const s = "the quick brown fox jumps over the lazy dog";
int n = 5, m = 3, i;
enum n = 5, m = 3;


writefln("%s", str[n..n+m]);
writeln(s[n .. n + m]);


writefln("%s", str[n..$]);
writeln(s[n .. $]);


writefln("%s", str[0..$-1]);
writeln(s[0 .. $ - 1]);


i = str.indexOf("q");
const i = s.indexOf("q");
writefln("%s", str[i..i+m]);
writeln(s[i .. i + m]);


i = str.indexOf("qu");
const j = s.indexOf("qu");
writefln("%s", str[i..i+m]);
writeln(s[j .. j + m]);
}</lang>
}</lang>
Output:
Output: