Quantcast
Viewing all articles
Browse latest Browse all 3

Answer by Shepmaster for How do I remove line feeds / line breaks from std::string::String?

First, you have to define what a "line feed" is. I choose the character \n. In that case, I'd just use replace:

println!("{}", string.replace('\n', ""))

This works for for &str and String.

If you didn't need a new string, I'd split on newlines and print them out:

pub fn minify(string: &str) {
    for line in string.split('\n') {
        print!("{}", line);
    }
}

Viewing all articles
Browse latest Browse all 3

Trending Articles