I found this in the Ruby documentation and thought I could refine my code:
“hello”.gsub(/[aeiou]/, ‘#’) => “h#ll#”
This is my code now, but it doesn’t work as I expected.
print “Your sentence:”
user_input = gets.chomp
if user_input.include? “s” || “S” || “c”
user_input.gsub!(/[cs]/, “th”)
user_input.gsub!(/S/, “Th”)
else puts “There are no s in your sentence.”
end
Before, it looked like this and worked:
print “Your sentence:”
user_input = gets.chomp
if user_input.include? “s” || “S” || “c”
user_input.gsub!(/s/, “th”)
user_input.gsub!(/S/, “Th”)
user_input.gsub!(/c/, “th”)
else puts “There are no s in your sentence.”
end
If we want to replace a world like, “Find” must be replaced by “search” so how to do that., should we write like
if user_input.include?“find” (OR) if user_input.include?“f” || “i” || “n”|| “d”
and if so it works plz show how it does. Even in ideone it is not working… Neither the above example nor the requests of mine
But this kind of code works for me well, using && but hope this is not the best practice…and it would be helpful if someone find a better way for it
print “Your sentence:”
user_input = gets.chomp
if user_input.include? “s” || “S” || “c”
user_input.gsub!(/s/, “th”) && user_input.gsub!(/S/, “Th”) && user_input.gsub!(/c/, “th”)
else puts “There are no s in your sentence.”
end