Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ALLOWED_OPERATION_CHARS: &'static [char] = &[
- '(', ')', '+', '-', '%', '/', '*'
- ];
- fn main() {
- let text = String::from("2*(2*2)");
- let iter = text.chars().into_iter();
- iter.map(|x| {
- if ALLOWED_OPERATION_CHARS.iter().any(|y| y.to_owned() == iter.clone().next().unwrap_or(' ')) {
- format!("{} ", x)
- } else {
- x.to_string()
- }
- }).collect::<String>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement