$ irb irb(main):001:0> str="[1,2][2,1][3,1][4,1]," => "[1,2][2,1][3,1][4,1]," irb(main):002:0> str.gsub(/\]\[/, '],[').sub(/,$/, '') => "[1,2],[2,1],[3,1],[4,1]" -- Kent On 3/2/06, huseyin polat <huseyinpolat / gmail.com> wrote: > I have spend over 4 hours for this.. here is the question masters, very > simple. > str=String.new > str="[1,2][2,1][3,1][4,1]" > > now I want to print this string as > [1,2],[2,1],[3,1],[4,1] > in other word I want to add comma between those ][ and make them look > like ],[ > I tried gsub with hundred different possibilities but no luck, > > second problem > if my the same str has > [1,2][2,1][3,1][4,1], > and I want to get rid of last comma from the list, I tried chop chomp > and all that but it gets ri of alot more than comma at the end. how can > I get rid of last comma from the list? from [1,2][2,1][3,1][4,1], to > [1,2][2,1][3,1][4,1] > > > any help will be appreciated. > thank you > > > -- > Posted via http://www.ruby-forum.com/. > >