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);
}
}