rustlings/exercises/09_strings/strings4.rs

37 lines
1,023 B
Rust
Raw Normal View History

2024-06-22 13:51:21 +03:00
// Calls of this function should be replaced with calls of `string_slice` or `string`.
fn placeholder() {}
2022-07-14 14:01:40 +03:00
fn string_slice(arg: &str) {
2024-06-22 13:51:21 +03:00
println!("{arg}");
2022-07-14 14:01:40 +03:00
}
fn string(arg: String) {
2024-06-22 13:51:21 +03:00
println!("{arg}");
2022-07-14 14:01:40 +03:00
}
2024-06-22 13:51:21 +03:00
// TODO: Here are a bunch of values - some are `String`, some are `&str`.
// Your task is to replace `placeholder(…)` with either `string_slice(…)`
// or `string(…)` depending on what you think each value is.
2022-07-14 14:01:40 +03:00
fn main() {
2024-06-22 13:51:21 +03:00
placeholder("blue");
placeholder("red".to_string());
placeholder(String::from("hi"));
placeholder("rust is fun!".to_owned());
placeholder("nice weather".into());
placeholder(format!("Interpolation {}", "Station"));
// WARNING: This is byte indexing, not character indexing.
// Character indexing can be done using `s.chars().nth(INDEX)`.
placeholder(&String::from("abc")[0..1]);
placeholder(" hello there ".trim());
placeholder("Happy Monday!".replace("Mon", "Tues"));
placeholder("mY sHiFt KeY iS sTiCkY".to_lowercase());
2022-07-14 14:01:40 +03:00
}