Skip to content

Commit

Permalink
Add string 1 - 4
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldww committed May 2, 2023
1 parent c9c5602 commit fe56fe9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
2 changes: 0 additions & 2 deletions exercises/enums/enums3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Address all the TODOs to make the tests pass!
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

use self::Message::*;

enum Message {
Expand Down
4 changes: 1 addition & 3 deletions exercises/strings/strings1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Make me compile without changing the function signature!
// Execute `rustlings hint strings1` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

fn main() {
let answer = current_favorite_color();
println!("My current favorite color is {}", answer);
}

fn current_favorite_color() -> String {
"blue"
String::from("blue")
}
4 changes: 1 addition & 3 deletions exercises/strings/strings2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Make me compile without changing the function signature!
// 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.");
Expand Down
11 changes: 3 additions & 8 deletions exercises/strings/strings3.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// strings3.rs
// 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!
???
String::from(input.trim())
}

fn compose_me(input: &str) -> String {
// TODO: Add " world!" to the string! There's multiple ways to do this!
???
format!("{input} world!")
}

fn replace_me(input: &str) -> String {
// TODO: Replace "cars" in the string with "balloons"!
???
String::from(input.replace("cars", "balloons"))
}

#[cfg(test)]
Expand Down
22 changes: 10 additions & 12 deletions exercises/strings/strings4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// before the parentheses on each line. If you're right, it will compile!
// No hints this time!

// I AM NOT DONE

fn string_slice(arg: &str) {
println!("{}", arg);
}
Expand All @@ -16,14 +14,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());
}

0 comments on commit fe56fe9

Please sign in to comment.