Any ideas on how to replace a verticle white space?
for example
tetetetetetetete
tetetettetetetete
rererererererere
rerererererererr
such that you end up with
tetetetetetetettete
etetetetetetetetete
rererererererererer
erererererererereer
Thank you
puts s.gsub(/\r\n(\r\n)+/,“\r\n\r\n”)
Just adjust the number of \r\n
p.s. have a look mainly at (\r\n)+ : a serie of one or more \r\n
2009/7/17 George G. [email protected]
At 2009-07-17 08:11AM, “Mirko Viviani” wrote:
2009/7/17 George G. [email protected]
Any ideas on how to replace a verticle white space?
[…]
puts s.gsub(/\r\n(\r\n)+/,“\r\n\r\n”)
I would write:
s.gsub(/((?:\r?\n){2})(?:\r?\n)*/, ‘\1’)
In Ruby, are newlines represented just as “\n” regardless of your
platform?
Well… I just tried out with \r\n… neverthless the solution is the
same
2009/7/17 Glenn J. [email protected]
Hi,
Thanks you for the replies. Both approaches did not seem to achieve what
i envisaged. Is because of reading the input as a string? rather than as
a file?
Maybe to rephrase what i really wanted was to be able to delete the
repeated lines and only remain with a single empty line.
meaning if a file had the lines;
tetetetetetetete
tetetettetetetete
rererererererere
rerererererererr
remove the empty lines leaving only a single one
tetetetetetetete
tetetettetetetete
rererererererere
rerererererererr
Thank you
George
On Thu, Jul 23, 2009 at 8:12 AM, George
George[email protected] wrote:
rererererererere
rerererererererr
Do you have a more specific test case (with code) that is failing?
Reading from a file and using Glenn J.'s gsub, seems to produce
your desired output:
cat z
tetetetetetetete
tetetettetetetete
rererererererere
rerererererererr
ruby -ve ‘puts File.new(“z”).read.gsub(/((?:\r?\n){2})(?:\r?\n)*/, “\1”)’
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux]
tetetetetetetete
tetetettetetetete
rererererererere
rerererererererr
unix2dos z
unix2dos: converting file z to DOS format …
ruby -ve ‘puts File.new(“z”).read.gsub(/((?:\r?\n){2})(?:\r?\n)*/, “\1”)’
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux]
tetetetetetetete
tetetettetetetete
rererererererere
rerererererererr