Comprehensive Ruby Programming
上QQ阅读APP看书,第一时间看更新

Using the strip method

Let's start off by analyzing the strip method. Imagine that the input you get from the user or from the database is poorly formatted and contains white spaces before and after the value. To clean the data up, we can use the strip method. Consider this example:

str = "  The quick brown fox jumped over the quick dog  " 
p str.strip

When you run this code, the output is just the sentence without the white spaces before and after the words: