full_name = "My Name is Ravikanth\r\n"
full_name.chop! # => "My Name is Ravikanth"
Now if you run chop and there are no newline characters.
puts full_name #=> "My Name is Ravikanth"
full_name.chop! #=> "My Name is Ravikant"
Disaster Strikes!
That’s why there is chomp.
puts full_name #=> "My Name is Ravikanth\r\n"
full_name.chomp! #=> "My Name is Ravikanth"
full_name.chomp! #=> "My Name is Ravikanth"
So chomp is our recommended way of removing trailing newline characters.
Nice
ReplyDelete