Logo

Programming-Idioms

History of Idiom 137 > diff from v17 to v18

Edit summary for version 18 by Alfriadox:
New Rust implementation by user [Alfriadox]

Version 17

2017-09-12, 15:06:21

Version 18

2017-12-06, 13:54:39

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);
Demo URL
https://play.rust-lang.org/?gist=9ca489c1de25feb2f09a1770e40b62b1&version=stable