Center, left justify and right justify string : String format « String « Ruby






Center, left justify and right justify string


s = "Some text."
s.center(15)                    # => "  Some text.   "
s.ljust(15)                     # => "Some text.     "
s.rjust(15)                     # => "     Some text."

 








Related examples in the same category

1.use % for format printing
2.Substituting Variables Into an Existing String
3.Replace string with float
4.Changing the Case of a String