parseDelimited

Parses string input, delimited by character delimiter, into a tuple of variables $(arg).

@safe
void
parseDelimited
(
Data
)
(
const string input
,
const char delimiter
,
ref Data arg
)

Return Value

Type: void

On success, the function returns nothing (void), and all the members of the tuple are populated.

Throws

std.std.exception.Exception. on failure to correctly parse the string.

Examples

string s = "Hello World 42";
Tuple!(string,string,int) t;
parseDelimited(s,' ',t);
assert(t[0]=="Hello");
assert(t[1]=="World");
assert(t[2]==42);

Notes:

  1. Parsing is much stricter (and less tolerant) than std.std.format.formattedRead.
  2. White-space is never automatically skipped
  3. A space delimiter consume only space character (ASCII 20), not TAB (ASCII 9)
  4. Multiple consecutive delimiters are not consumed as one delimiter (e.g. "1\t\t\t2" is considerd a string with four fields - it has three delimiters. It will throw an exception because empty fields are not allowed).
  5. All fields must exist (i.e. if the tuple arg has 3 members, the input string must contain two delimiters and three valid values)
  6. For a string field, empty values are not acceptable, will throw an exception
  7. Extra characters at the end of a field or the line will throw an exception

Meta