Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby fails to detect newline character in a string

I have the following string and I want to detect the newline character there. But the Ruby's string method include? fails to detect it.

I am running Ruby 1.9.2p290. Where am I going wrong there?

"/'ædres/ \nYour ".include?('\n')
 => false 
like image 903
steveyang Avatar asked Jun 11 '12 17:06

steveyang


1 Answers

\n needs to be in a double quoted string, otherwise there'll be no escaping.

>> "\n".include? '\n'
=> false
>> "\n".include? "\n"
=> true
like image 54
Michael Kohl Avatar answered Oct 06 '22 21:10

Michael Kohl