formattedRead

Reads characters from input range r, converts them according to fmt, and writes them to args.

  1. uint formattedRead(R r, S args)
  2. uint formattedRead(R r, const(Char)[] fmt, S args)
    uint
    formattedRead
    (
    R
    Char
    S...
    )
    (
    auto ref R r
    ,
    const(Char)[] fmt
    ,
    auto ref S args
    )

Parameters

r R

The range to read from.

fmt const(Char)[]

The format of the data to read.

args S

The drain of the data read.

Return Value

Type: uint

On success, the function returns the number of variables filled. This count can match the expected number of readings or fewer, even zero, if a matching failure happens.

Throws

A FormatException if S.length == 0 and fmt has format specifiers.

Examples

The format string can be checked at compile-time (see format for details):

string s = "hello!124:34.5";
string a;
int b;
double c;
s.formattedRead!"%s!%s:%s"(a, b, c);
assert(a == "hello" && b == 124 && c == 34.5);

Meta

Suggestion Box / Bug Report