On Wednesday, 21 February 2018 at 10:24:39 UTC, ketmar wrote:
0xFFFFFFFF wrote:
[...]
and that is exactly what slices are for! ;-)
you are probably better to use `const(char)[]`, tho. like this:
// don't store `s`, as it's contents may change after exiting
of `myfunc`
// (this is what `const` implies here)
void myfunc (const(char)[] s) { ... }
...
string s = "test string";
myfunc(s); // yep, this works
s = s[2..4]; // this doesn't allocate
myfunc(s);
myfunc(s[3..6]); // or this, it doesn't allocate
myfunc("abc"); // or this, doesn't allocate
you got the idea.
Gotta save this too.
[BTW how do I post a thumbs up emoji]