From: Stu Date: 2011-03-29T05:01:43+09:00 Subject: Re: How to "find" new lines don't know if this will help you but ruby 1.9 has the each_line method. example: def line_count( s) c = 0 s.each_line { |l| c+=1 } return( c) end >>line_count( "I am \na multi\nline\nstring!") => 4 if you want to test against the ascii equivalent in 1.8.7 it's ?\n and in 1.9.2 it's "\n".ord which should return 10 in decimal format. On Fri, Mar 25, 2011 at 3:28 PM, Damir Sigur wrote: > I am new to ruby, and was trying to make a small code which would check > if a string has only new line character in it. At the end I found that a > method "inspect" will do the trick. > > Is that the only way to handle new line characters? > > How about other special characters, if there is a need to search for > them in a text? > > Code that didn't work: > > if txtArray[i] <=> "\n" then > > Code that worked: > > if txtArray[i].inspect <=> "\n" then > > Thanks for all comments. > > -- > Posted via http://www.ruby-forum.com/. > >