What to use instead of array.join if RHS is not a range?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Nov 27 14:48:37 PST 2012
On Tuesday, November 27, 2012 23:35:55 Andrej Mitrovic wrote:
> On 11/27/12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> > Rather, you're asking it to insert an element
> > between
> > every element in range, which is similar but not the same.
>
> In that case, which function to use? Because it already behaves in
> this way for strings.
But it doesn't. It requires a range of ranges, and a string is a range of
dchar. You need a range of strings to use join on strings.
assert(join(["hello", "silly", "world"], " ") == "hello silly world");
will work.
assert(join("hello world", " ") == "h e l l o w o r l d");
won't. You seem to be looking for a function which will insert an element
between every element in a range rather than one that joins ranges, and I'm
not aware of any function in Phobos which will do that. There may be a way to
get one to do what you want, but I can't think of how at the moment.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list