Format strings like PRINT USING


/ Published in: Ruby
Save to your folder(s)

This is an extension to Ruby's String class. Just put this code in a file and include it. This basically takes a string and adds literals and padding to it. For example, you can format a phone number with optional area code like this:

"5445556747".using('(###) ###-####', '', true)
=> (544) 555-6747

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.