Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: issue with stripping tabs Date: Sat, 23 Nov 2013 13:22:43 +0100 Lines: 40 Message-ID: References: <5d694d88-a4cb-4129-a4c5-b9de5f9dd4bb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net riQIgaE0pdqBEDwBaNVEAwsWMQf/wCzFD9B9mvJHQUIS2bYkQ= Cancel-Lock: sha1:SBvRvcTAnAak2tJqDcS99PTuwUk= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <5d694d88-a4cb-4129-a4c5-b9de5f9dd4bb@googlegroups.com> X-Antivirus: avast! (VPS 131122-0, 22.11.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.ruby:6893 On 23.11.2013 10:07, helmut_blass@web.de wrote: > without success I try to strip leading and trailing tabs: > I tried: > str.gsub(/\s+/, "") > str.gsub(/\t/, "") > str.strip.gsub(/\t/, "") > > none of them works. > > any suggestions? Where's your problem? They all work - in a way irb(main):004:0> strings=["a", "\ta", "a\t", "\ta\tb\t"] => ["a", "\ta", "a\t", "\ta\tb\t"] irb(main):005:0> strings.map {|str| str.gsub(/\s+/, "")} => ["a", "a", "a", "ab"] irb(main):006:0> strings.map {|str| str.gsub(/\t/, "")} => ["a", "a", "a", "ab"] irb(main):007:0> strings.map {|str| str.strip.gsub(/\t/, "")} => ["a", "a", "a", "ab"] You might want to do irb(main):008:0> strings.map {|str| str.sub(/\A\t+/, "").sub(/\t+\z/, "")} => ["a", "a", "a", "a\tb"] But #strip is much simpler, even though it removes other whitespace as well: irb(main):009:0> strings.map {|str| str.strip} => ["a", "a", "a", "a\tb"] Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/