parse

Parses a character input range to an integral value.

Parameters

Target

the integral type to convert to

s Source

the lvalue of an input range

Return Value

Type: Target

A number of type Target

Throws

A ConvException If an overflow occurred during conversion or if no character of the input was meaningfully converted.

Examples

string s = "123";
auto a = parse!int(s);
assert(a == 123);

// parse only accepts lvalues
static assert(!__traits(compiles, parse!int("123")));
import std.string : tr;
string test = "123 \t  76.14";
auto a = parse!uint(test);
assert(a == 123);
assert(test == " \t  76.14"); // parse bumps string
test = tr(test, " \t\n\r", "", "d"); // skip ws
assert(test == "76.14");
auto b = parse!double(test);
assert(b == 76.14);
assert(test == "");

Meta

Suggestion Box / Bug Report