string to thread

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 8 02:10:42 PDT 2012


On Saturday, September 08, 2012 11:01:50 monarch_dodra wrote:
> In C++ (not C), when you wanted to parse a string, you were
> supposed to put the string inside a stream (std::stringstream),
> and then parse that new stream stream.
> 
> As a general rule, stringstream also allowed abstracting a string
> into a more generic stream.
> 
> I did not find anything equivalent in D. Did I just miss it?
> 
> How is a user supposed to parse a string in D?
> 
> I thought I was supposed to use "formattedRead", but was told
> that was actually more meant for library writers. Is there an
> alternative? Just trying to learn.

If you were to operate on a string in a manner similar to a stream, you'd be 
operating on it as a range, and there are a lot of range-based functions in 
Phobos. But if you want to specifically parse a range of characters, then use 
std.conv.parse:

http://dlang.org/phobos/std_conv.html#parse

If you want to know more about ranges, then this is currently the best 
tutorial on them:

http://ddili.org/ders/d.en/ranges.html

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list