I was just paying taxes ?. One of the steps involved was copying and pasting a few long reference numbers from a PDF into my banking app. The thing is, when copied, the reference number would contain extra spaces, after each character, making it invalid where I needed to paste it.
Now there are myriad of different solutions for this I’m sure, but as a programmer, let’s take a look at how to speedily create a makeshift tool in Ruby to do this.
1 2 | irb space_eater = ->(text) { text.gsub( ' ' , '' ) } |
We launched into the interactive shell, and defined a lambda we can call on strings we want to sanitize. Like so:
1 2 | space_eater.call( '2 3 9 2 9 9 A 8 2 8 0 0 0 1' ) => "239299A8280001" |
And we’re done. ❤️ Ruby.