Logo

Programming-Idioms

History of Idiom 137 > diff from v8 to v9

Edit summary for version 9 by BBaz:
New D implementation by user [BBaz]

Version 8

2016-06-25, 22:38:56

Version 9

2016-08-13, 21:11:22

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Imports
std.algorithm.iteration;
std.ascii;
Code
bool b = s.filter!(a => !isDigit(a)).empty;�
Comments bubble
the result of filter is a lazy range. we know that only digits are present if this range is empty.
Demo URL
https://dpaste.dzfl.pl/ff158570abab