Add some exercises about Strings and &strs!

This commit is contained in:
Carol (Nichols || Goulding)
2015-09-20 18:03:00 -04:00
parent ce3b710b13
commit 93869014f4
4 changed files with 114 additions and 0 deletions

18
strings/strings3.rs Normal file
View File

@@ -0,0 +1,18 @@
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
// task is to call one of these two functions on each value depending on what
// you think each value is. That is, add either `string_slice` or `string`
// before the parentheses on each line. If you're right, it will compile!
fn string_slice(arg: &str) { println!("{}", arg); }
fn string(arg: String) { println!("{}", arg); }
fn main() {
("blue");
("red".to_string());
(String::from("hi"));
(format!("Interpolation {}", "Station"));
(&String::from("abc")[0..1]);
(" hello there ".trim());
("Happy Monday!".to_string().replace("Mon", "Tues"));
("mY sHiFt KeY iS sTiCkY".to_lowercase());
}