Is there a chomp like Perl operator in Ruby using which I can literally
remove new line characters as show below in my Perl script:
use strict;
use warnings;
my $str1 = “Hello\n”;
my $str2 = “World”;
print $str1.$str2;
print “\n”;
chomp($str1);
print $str1.$str2;
print “\n”;
Any clue?
On Sat, May 15, 2010 at 2:26 PM, Parag K. [email protected]
wrote:
Is there a chomp like Perl operator in Ruby using which I can literally
remove new line characters as show below in my Perl script:
There’s a really easy way to answer this question for yourself:
$ ri chomp
(from ruby core)
Implementation from String
str.chomp(separator=$/) => new_str
Returns a new String with the given record separator removed from the
end of str (if present). If $/ has not been changed from the
default Ruby record separator, then chomp also removes carriage return
characters (that is it will remove n, r, and r\n).
On Sat, May 15, 2010 at 4:26 PM, Parag K. [email protected]
wrote:
Posted via http://www.ruby-forum.com/.
The online docs (plus a few examples) for the method Ben showed the ri
of
http://ruby-doc.org/core/classes/String.html#M000819
Thanks it worked:
str=“Hello\n”
str2=“World”
puts str+str2
str1=str.chomp
puts str1+str2
On Saturday, May 15, 2010 04:34:20 pm Ben B. wrote:
On Sat, May 15, 2010 at 2:26 PM, Parag K. [email protected] wrote:
Is there a chomp like Perl operator in Ruby using which I can literally
remove new line characters as show below in my Perl script:
There’s a really easy way to answer this question for yourself:
$ ri chomp
Not the whole story. If you know you’re not going to use the original
string,
you might consider chomp! instead.