Alex Rivera | Logout

How to remove newLines at the beginning and at the end of a Ruby string

Asked 2011-08-23T20:30:58.817
28

I need to remove newlines at the beginning and at the end of a string in ruby (some sort of trimming).

But JUST at the beginning and the end... The new lines located in the middle of the string must remain untouched.

Thank you!

Edit
Report

1 Answer

2

This should do it:

string.lstrip!.rstrip!
answered 2011-08-23T20:38:58.480

Your Answer