From: William James Date: 2007-01-23T12:01:56+09:00 Subject: Re: Problems with replacing text Sam C. wrote: > I am creating a small chatbot program in Ruby, and I need it to be able > to change the word "I" to "You" when it is reading the user input. this > is the code I am using: > > uinput['I'] = 'you' > > The problem is, whenever I enter text that doesn't include the word "I", > an error is printed out and the program terminates. I am looking for a > way to work around this, possibly a command that ignores the error, or > an If-Then statement that checks to see if "I" exists before replacing > it. irb(main):005:0> input = "I see. In fact, I understand." => "I see. In fact, I understand." irb(main):006:0> input.gsub!( /\bI\b/, "you" ) => "you see. In fact, you understand."