chop removes trailing character or line terminator (\n, \r, or \r\n) : chop « String « Ruby






chop removes trailing character or line terminator (\n, \r, or \r\n)


s = "hello\n"
s.chop!              # => "hello": line terminator removed. s modified.
s.chop               # => "hell": last character removed. s not modified.
"".chop              # => "": no characters to remove
"".chop!             # => nil: nothing changed

 








Related examples in the same category

1.Call shop function from string class
2.chop removes the last character (a quote) with abandon