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?
···
--
Posted via http://www.ruby-forum.com/.
There's a really easy way to answer this question for yourself:
$ ri chomp
(from ruby core)
Implementation from String
···
On Sat, May 15, 2010 at 2:26 PM, Parag Kalra <paragkalra@gmail.com> 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:
------------------------------------------------------------------------------
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).
The online docs (plus a few examples) for the method Ben showed the ri of
http://ruby-doc.org/core/classes/String.html#M000819
···
On Sat, May 15, 2010 at 4:26 PM, Parag Kalra <paragkalra@gmail.com> 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:
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?
--
Posted via http://www.ruby-forum.com/\.
Thanks it worked:
str="Hello\n"
str2="World"
puts str+str2
str1=str.chomp
puts str1+str2
···
--
Posted via http://www.ruby-forum.com/.
Not the whole story. If you know you're not going to use the original string,
you might consider chomp! instead.
···
On Saturday, May 15, 2010 04:34:20 pm Ben Bleything wrote:
On Sat, May 15, 2010 at 2:26 PM, Parag Kalra <paragkalra@gmail.com> 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