From 13c442ec31bd1276d31473c4c63a536222955d3b Mon Sep 17 00:00:00 2001 From: Rock070 Date: Sat, 30 Dec 2023 16:49:44 +0800 Subject: [PATCH] Fix string manipulation functions --- exercises/09_strings/strings3.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exercises/09_strings/strings3.rs b/exercises/09_strings/strings3.rs index b29f9325..d20ed963 100644 --- a/exercises/09_strings/strings3.rs +++ b/exercises/09_strings/strings3.rs @@ -3,21 +3,23 @@ // 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! - ??? + let mut s = String::new(); + s.push_str(input); + s.push_str(" world!"); + + s } fn replace_me(input: &str) -> String { // TODO: Replace "cars" in the string with "balloons"! - ??? + input.replace("cars", "balloons") } #[cfg(test)]