Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > replacing verticle white spaces?

Reply
Thread Tools

replacing verticle white spaces?

 
 
George George
Guest
Posts: n/a
 
      07-17-2009
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Mirko Viviani
Guest
Posts: n/a
 
      07-17-2009
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 George <>

> 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
> --
> Posted via http://www.ruby-forum.com/.
>
>



--=20
-- Mirko Viviani --
GPG-PGP Public Key: 0xE4E8FAB1
Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
***********************************************
"=93Machines take me by surprise with great frequency.=94 A. Turing

 
Reply With Quote
 
 
 
 
Mirko Viviani
Guest
Posts: n/a
 
      07-17-2009
Well... I just tried out with \r\n.... neverthless the solution is the same


2009/7/17 Glenn Jackman <>

> At 2009-07-17 08:11AM, "Mirko Viviani" wrote:
> > 2009/7/17 George George <>
> > > 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?
>
> --
> Glenn Jackman
> Write a wise saying and your name will live forever. -- Anonymous
>
>



--=20
-- Mirko Viviani --
GPG-PGP Public Key: 0xE4E8FAB1
Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
***********************************************
"=93Machines take me by surprise with great frequency.=94 A. Turing

 
Reply With Quote
 
George George
Guest
Posts: n/a
 
      07-23-2009
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
brabuhr@gmail.com
Guest
Posts: n/a
 
      07-23-2009
On Thu, Jul 23, 2009 at 8:12 AM, George George<> wrote:
> 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


Do you have a more specific test case (with code) that is failing?
Reading from a file and using Glenn Jackman'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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
verticle alignment of text to bottom of (printed) page Jim in Arizona ASP .Net 2 06-07-2008 10:23 AM
Missing Text When Printing Page With <iframe> Using Verticle Scroll.... Is There A Workaround??? Philip Ronan HTML 2 01-31-2006 03:07 PM
Datagrid Verticle Header is this possible? How? Roger ASP .Net 4 03-23-2005 06:13 PM
Radeon 9600 - verticle lines on TV Out Tiny Tim Computer Support 26 03-21-2005 01:16 PM
thin verticle white line appears on printed picture Brian Digital Photography 6 10-11-2004 02:31 AM



Advertisments