In Rust, you can split a string by new line using the lines
method.
In this example,
str
with a value containing new lines.lines
method to split the string into an iterator of substrings.fn main() {
let str = "Hello\nWorld\n";
for line in str.lines() {
println!("{}", line);
}
}
Hello World
In this tutorial, we learned How to Split a String by New Line in Rust language with well detailed examples.