From: Joel Pearson Date: 2012-10-17T16:52:20+09:00 Subject: Re: Drop 1st and last particular character Sagy Drucker wrote in post #1080132: > You didn't mention what if you have three times '#'. > e.g. input = "#1234#567# > I assume you want output = "1234#567" > Use the String function "sub" which substitute from the first occurrence > only, on the input, > Then reverse the input and use it again (to remove last occurrence) > e.g.: > myString.sub!('#','') > myString.reverse!.sub!('#','').reverse! > This will keep all the '#' chars in between. > > Sagy No Sagy, that's not a good method: "1#1234#567#1".sub!('#','').reverse!.sub!('#','').reverse! => "11234#5671" -- Posted via http://www.ruby-forum.com/.