From: "David A. Black" Date: 2009-07-20T20:23:04+09:00 Subject: Re: How to strip inner whitespace in rails --1926193751-1840052100-1248088970=:5881 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1840052100-1248088970=:5881" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1840052100-1248088970=:5881 Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Mon, 20 Jul 2009, Xavier Noria wrote: > On Mon, Jul 20, 2009 at 5:15 AM, 7stud -- wrote: > >> split() rules the world.  squeez()...not so much. > > Why? String#squeeze performs precisely what the OP asks for. There's > nothing as concise as that. > > If what needs to be collapsed is whitespace in the \s sense, then I > would perhaps swtich to gsub: > > str.gsub(/\s+/, ' ') I agree, unless speed is an issue, in which case you might be better off with: str.squeeze(" \t\n\r\f") although it's a bit more heavy-handed and I'm probably forgetting one. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN) --1926193751-1840052100-1248088970=:5881-- --1926193751-1840052100-1248088970=:5881--