Gistlib Logo

gistlib

rust 字符串以换行符分割成vec in rust

main.rs
fn main() {
    let s = String::from("Hello\nWorld\nRust");
    let lines: Vec<&str> = s.lines().collect();
    
    println!("{:?}", lines);
}
144 chars
7 lines

similar rust code snippets

find the last index of a substring in a string in rust
find the last index of a character in a string in rust
replace a character in a string in rust
prepend a string to the beginning of another string in rust
format a date in to the format 'yyyy-mm-dd hh:mm:ss' in rust
remove a substring from a string in rust
create a template string in rust
split a string into an array of substrings in rust
find the first index of a character in a string in rust
remove an element from the end of an array in rust

related categories

rust
string
vector

gistlibby LogSnag