A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Remove All Whitespace in Rust page! Here, you'll find the source code for this program as well as a description of how the program works.
use std::env::args;
use std::process::exit;
fn usage() -> ! {
println!("Usage: please provide a string");
exit(0);
}
fn remove_all_whitespaces(s: String) -> String {
s.chars().filter(|c| !c.is_whitespace()).collect()
}
fn main() {
let mut args = args().skip(1);
// Get first command-line argument
let s: String = args
.next()
.unwrap_or_else(|| usage());
// Make sure not empty
if s.len() < 1 {
usage();
}
// Remove all whitespace and show results
let t: String = remove_all_whitespaces(s);
println!("{t}");
}
Remove All Whitespace in Rust was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.