Tutorial by Examples

fn main() { // Statically allocated string slice let hello = "Hello world"; // This is equivalent to the previous one let hello_again: &'static str = "Hello world"; // An empty String let mut string = String::new(); // An empty String ...
fn main() { let english = "Hello, World!"; println!("{}", &english[0..5]); // Prints "Hello" println!("{}", &english[7..]); // Prints "World!" } Note that we need to use the & operator here. It takes a reference and ...
let strings = "bananas,apples,pear".split(","); split returns an iterator. for s in strings { println!("{}", s) } And can be "collected" in a Vec with the Iterator::collect method. let strings: Vec<&str> = "bananas,apples,pear"....
// all variables `s` have the type `String` let s = "hi".to_string(); // Generic way to convert into `String`. This works // for all types that implement `Display`. let s = "hi".to_owned(); // Clearly states the intend of obtaining an owned obje...
Break regular string literals with the \ character let a = "foobar"; let b = "foo\ bar"; // `a` and `b` are equal. assert_eq!(a,b); Break raw-string literals to separate strings, and join them with the concat! macro let c = r"foo\bar"; let d = conca...

Page 1 of 1