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