steveyang
steveyang

Reputation: 9288

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 

Upvotes: 7

Views: 8020

Answers (1)

Michael Kohl
Michael Kohl

Reputation: 66837

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

>> "\n".include? '\n'
=> false
>> "\n".include? "\n"
=> true

Upvotes: 21

Related Questions