Logo

Programming-Idioms

History of Idiom 137 > diff from v18 to v19

Edit summary for version 19 by Alfriadox:
[Rust] Removed example value.

Version 18

2017-12-06, 13:54:39

Version 19

2017-12-06, 13:55:13

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.

Code
let s = "1023";
let chars_are_numeric: Vec<bool> = s.chars()
				.map(|c|c.is_numeric())
				.collect();
let b = !chars_are_numeric.contains(&false);
Code
let chars_are_numeric: Vec<bool> = s.chars()
				.map(|c|c.is_numeric())
				.collect();
let b = !chars_are_numeric.contains(&false);
Demo URL
https://play.rust-lang.org/?gist=9ca489c1de25feb2f09a1770e40b62b1&version=stable
Demo URL
https://play.rust-lang.org/?gist=9ca489c1de25feb2f09a1770e40b62b1&version=stable