strings done
This commit is contained in:
parent
da76123b1f
commit
bec1d3215d
|
@ -5,7 +5,6 @@
|
|||
// Execute `rustlings hint strings1` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let answer = current_favorite_color();
|
||||
|
@ -13,5 +12,5 @@ fn main() {
|
|||
}
|
||||
|
||||
fn current_favorite_color() -> String {
|
||||
"blue"
|
||||
"blue".to_string()
|
||||
}
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
// Execute `rustlings hint strings2` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let word = String::from("green"); // Try not changing this line :)
|
||||
if is_a_color_word(word) {
|
||||
if is_a_color_word(&word) {
|
||||
println!("That is a color word I know!");
|
||||
} else {
|
||||
println!("That is not a color word I know.");
|
||||
|
|
|
@ -3,21 +3,20 @@
|
|||
// Execute `rustlings hint strings3` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn trim_me(input: &str) -> String {
|
||||
// TODO: Remove whitespace from both ends of a string!
|
||||
???
|
||||
input.trim().to_string()
|
||||
}
|
||||
|
||||
fn compose_me(input: &str) -> String {
|
||||
// TODO: Add " world!" to the string! There's multiple ways to do this!
|
||||
???
|
||||
input.to_string() + " world!"
|
||||
}
|
||||
|
||||
fn replace_me(input: &str) -> String {
|
||||
// TODO: Replace "cars" in the string with "balloons"!
|
||||
???
|
||||
input.replace("cars", "balloons")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
//
|
||||
// No hints this time!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn string_slice(arg: &str) {
|
||||
println!("{}", arg);
|
||||
|
@ -17,14 +16,14 @@ fn string(arg: String) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
???("blue");
|
||||
???("red".to_string());
|
||||
???(String::from("hi"));
|
||||
???("rust is fun!".to_owned());
|
||||
???("nice weather".into());
|
||||
???(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());
|
||||
string_slice("blue");
|
||||
string("red".to_string());
|
||||
string(String::from("hi"));
|
||||
string("rust is fun!".to_owned());
|
||||
string_slice("nice weather".into());
|
||||
string(format!("Interpolation {}", "Station"));
|
||||
string_slice(&String::from("abc")[0..1]);
|
||||
string_slice(" hello there ".trim());
|
||||
string("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue