On Thursday, 9 January 2014 at 19:05:19 UTC, Adam D. Ruppe wrote:
On Thursday, 9 January 2014 at 18:57:26 UTC, Craig Dillabaugh
wrote:
A while ago I was trying to do something with splitter on a
string and I ended up asking a question on D.learn. [...]
It would be nice if std.string in D provided a nice, easy,
string manipulation that swept most of the difficulties under
the table
http://dlang.org/phobos/std_array.html#split
Note that std.array is publicly imported from std.string so
this works:
void main() {
import std.string;
auto parts = "hello".split("l");
import std.stdio;
writeln(parts);
}
provided links in the documentation to the functions they wrap
for when people want to do more complex things.
Actually, when writing my D book, I decided to spend more time
on the unicode stuff in strings than these basic operations,
since I thought these were pretty straightforward.
But maybe the docs suck more than I thought. I learned most of
D string stuff from Phobos1 which kept it all simple...
Thats the thing. In most cases the correct way to do something
in D, does end up being rather nice. However, its often a bit of
a challenge finding the that correct way!
When I had my troubles I expected to find the library solutions
in std.string (remember I rarely use D's string processing
utilities). It never really occurred to me that I might want to
check std.array for the function I wanted. So what it std.array
is imported when I import std.string, as a programmer I still had
no idea 'split()' was there!
At the very least the documentation for std.string should say
something along the lines of:
"The libraries std.unicode and std.array also include a number of
functions that operate on strings, so if what you are looking for
isn't here, try looking there."