Logo

Programming-Idioms

History of Idiom 137 > diff from v9 to v10

Edit summary for version 10 by BBaz:
[D] sdgfdfgdsg

Version 9

2016-08-13, 21:11:22

Version 10

2016-08-13, 21:11:32

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;
Imports
std.algorithm.iteration;
std.ascii;
Code
bool b = s.filter!(a => !isDigit(a)).empty;�
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.
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
Demo URL
https://dpaste.dzfl.pl/ff158570abab