Prev: Camera_Project
Next: Formatting directory listings
From: brabuhr on 10 Aug 2010 14:52 On Tue, Aug 10, 2010 at 11:51 AM, David Ainley <wrinkliez(a)gmail.com> wrote: > Hey guys. I have an array full of strings. When I put the strings, it > looks like this http://pastebin.com/eeicUCqL which is okay, but it looks > a little sloppy to me. Is there a way I can get the strings to > dynamically space themselves so that they look evenly spaced? ala > http://pastebin.com/cRcG97sK ? Should I split each string into it's > separate parts, and then print them via format? Or something...? And for a different approach :) /tmp> cat i.rb str = Array.new str << "gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-05)" str << "gm-notify 0.9-0~ppa6 TomVetterlein (2009-05-15)" str << "gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-13)" str << "gm-notify 0.9+r39-1~ppa1 SeanStoops (2009-12-22)" str << "gm-notify 0.9-0~ppa7 NikolaKovacs (2009-09-27)" str << "gm-notify 0.8-0ppa2 TomVetterlein (2009-04-27)" x = IO.popen("column -t", "w+"){|p| p.puts str.join("\n") p.close_write p.read } puts x /tmp> ruby i.rb gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-05) gm-notify 0.9-0~ppa6 TomVetterlein (2009-05-15) gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-13) gm-notify 0.9+r39-1~ppa1 SeanStoops (2009-12-22) gm-notify 0.9-0~ppa7 NikolaKovacs (2009-09-27) gm-notify 0.8-0ppa2 TomVetterlein (2009-04-27)
From: Joseph E. Savard on 10 Aug 2010 14:58
Sweet! :-) > From: <brabuhr(a)gmail.com> > Reply-To: <ruby-talk(a)ruby-lang.org> > Date: Wed, 11 Aug 2010 03:52:46 +0900 > To: ruby-talk ML <ruby-talk(a)ruby-lang.org> > Subject: Re: changing the spacing in a string? > > On Tue, Aug 10, 2010 at 11:51 AM, David Ainley <wrinkliez(a)gmail.com> wrote: >> Hey guys. I have an array full of strings. When I put the strings, it >> looks like this http://pastebin.com/eeicUCqL which is okay, but it looks >> a little sloppy to me. Is there a way I can get the strings to >> dynamically space themselves so that they look evenly spaced? ala >> http://pastebin.com/cRcG97sK ? Should I split each string into it's >> separate parts, and then print them via format? Or something...? > > And for a different approach :) > > /tmp> cat i.rb > str = Array.new > str << "gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-05)" > str << "gm-notify 0.9-0~ppa6 TomVetterlein (2009-05-15)" > str << "gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-13)" > str << "gm-notify 0.9+r39-1~ppa1 SeanStoops (2009-12-22)" > str << "gm-notify 0.9-0~ppa7 NikolaKovacs (2009-09-27)" > str << "gm-notify 0.8-0ppa2 TomVetterlein (2009-04-27)" > > x = IO.popen("column -t", "w+"){|p| > p.puts str.join("\n") > p.close_write > p.read > } > > puts x > > /tmp> ruby i.rb > gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-05) > gm-notify 0.9-0~ppa6 TomVetterlein (2009-05-15) > gm-notify 0.10.2-1~ppa1 AlexanderHungenberg (2010-05-13) > gm-notify 0.9+r39-1~ppa1 SeanStoops (2009-12-22) > gm-notify 0.9-0~ppa7 NikolaKovacs (2009-09-27) > gm-notify 0.8-0ppa2 TomVetterlein (2009-04-27) > |