On Saturday, 29 December 2012 at 22:25:35 UTC, FG wrote:
Forgive me if such a function already exists -- I couldn't find it.

std.range have drop and take, which work on code points, not code units. They also handle over-dropping or over-taking gracefully. For example:

string s = "okrągły stół";
writeln(s.drop(8).take(3)); // "stó"
writeln(s.drop(8).take(100)); // "stół"
writeln(s.drop(100).take(100)); // ""

http://dpaste.dzfl.pl/2f8ebf49

It doesn't support negative indexing.

Generally speaking though, the vast majority of user code should never need to index into a Unicode string.

Reply via email to