From: Kyle Schmitt Date: 2008-06-11T03:26:37+09:00 Subject: Re: replacing a character in a string Umm, what exactly makes you think it isn't working? It is working, but for sub, not gsub. sub replaces the first, gsub replaces all Also, you don't need to do this in an if statement. If the underscore isn't present, sub and gsub won't complain. #Probably what you want. cal_name.gsub!('_',' ') Good luck, --Kyle On Tue, Jun 10, 2008 at 1:19 PM, Amanda .. wrote: > So I want to be able to take a string with underscores in it ('_') and > replace those with spaces...can somebody please tell me why this isn't > working: > > if cal_name.include? '_' > cal_name.sub!('_', ' ') > end > > I can't see why this isn't doing the trick...but maybe I'm doing > something wrong. If anyone could give me any idea of what's wrong..or > even a different approach, that would be great! > > Thanks > -- > Posted via http://www.ruby-forum.com/. > >