Ruby | Remove Whitespace in Strings

Опубликовано: 01 Октябрь 2024
на канале: REALLY FAST tutorials
759
27

In this video, I show how to remove leading and trailing whitespace from an array of strings using the Ruby programming language.

When first looking at this problem, my intuition was to use rstrip!, but this only removed characters that appeared at the end of strings. I was able to achieve the removal of both leading and trailing whitespace with strip!. Note that strip will not alter the array itself, but rather an instance of the array. This is demonstrated in the video.

Using strip!, I was able to convert ['welcome', ' to', 'my', ' channel', 'thanks '] to ['welcome', to', 'my', 'channel', 'thanks'].

As always, thank you for watching, and don't forget to subscribe if you found this helpful!

#Ruby #programming #technology