parse string as char
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 8 19:02:16 PST 2015
On 9/02/2015 3:40 p.m., Timothee Cour via Digitalmars-d-learn wrote:
> Is there a simple way to parse a string as a char?
> eg:
> unittest{
> assert(parseChar(`a`)=='a');
> assert(parseChar(`\n`)=='\n'); //NOTE: I'm looking at `\n` not "\n"
> // should also work with other forms of characters, see
> http://dlang.org/lex.html
> }
> Note, std.conv.to <http://std.conv.to> doesn't work (`\n`.to!char does
> not work)
Ugh, if you are just wanting to get a singular char in a string just you
slices.
assert("mystr"[0] == 'm');
More information about the Digitalmars-d-learn
mailing list