How to get the first line of a multi-line string in Rust

1 Answer

0 votes
fn main() {
    let multi_line_string = 
        "First line\n\
        Second line\n\
        Third line\n\
        Fourth line";

    let first_line = multi_line_string.split('\n').next().unwrap();

    println!("The first line is: {}", first_line);
}



    
/*
run:
 
The first line is: First line
 
*/

 



answered Aug 13, 2024 by avibootz
...