On Mon, Apr 4, 2011 at 3:18 PM, Steven Schveighoffer <schvei...@yahoo.com> wrote: > On Sun, 03 Apr 2011 14:24:33 -0400, spir <denis.s...@gmail.com> wrote: >> Agreed this is a fairly standard param in other languages, but D easily >> (and rather cheaply) allows >> auto pos = indexOf(s[i..$], char); > > That doesn't work, because it gets you the position in relation to s[i..$], > whereas you want the position in relation to s. >
This works: ----------------------------------------------------------- sizediff_t indexOf(Char, T = sizediff_t)(in Char[] s, dchar c, T sp = 0) if (isSomeChar!Char) { if (sp < 0) sp += s.length; if (sp >= 0 && sp < s.length) { auto i = indexOf(s[sp..$], c); if (i > -1) return i + sp; } return -1; } ----------------------------------------------------------- And it doesn't require change of existing indexOf.