From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Trim spaces

Challenge: Trim spaces - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Challenge: Trim spaces

(upbeat music) - [Instructor] All right folks it's time for our next challenge. To practice working with borrowed references and slices. Your goal is to write a function that removes any leading and trailing spaces from the beginning and end of a string. Your function should be named trim spaces, it should accept one input argument. That's either a string reference or a string slice and it should return a string slice with any leading and trailing spaces removed. Now, strings in Rust do include a built-in method named trim. Which removes leading and trailing white space. Using that would make this challenge trivial. So for the sake of practice I recommend writing your solution without it. The trim method removes multiple types of white space including new lines and tabs. But for this challenge let's just worry about removing the space character. After you've written your trim space function you can use this example…

Contents