我的任务是接受用户的输入并将每个'c'和's'更改为's'和'th'。更改用户输入,但分别存储原始输入
之后,它要求我存储原始用户的输入,以便它不会被更改。
我无法在Ruby中搞清楚。
print "What can we do for you?"
user_input = gets.chomp
user_input.downcase!
if user_input.length == 0
puts "Well you will have to write something...!"
elsif user_input.include?("s") || user_input.include?("c")
puts "We got ourselves some 's's and some 'c's"
user_input.gsub!(/s/, "th")
user_input.gsub!(/c/, "s")
puts "The changed version: '#{user_input}!'"
else
print "Nope, no 's' or 'c' found"
end
[那样?](https://repl.it/C1lw) – potashin
这是功课吗?如果是这样,请阅读http://meta.programmers.stackexchange.com/questions/6166/open-letter-to-students-with-homework-problems,http://meta.stackoverflow.com/q/261592/128421和http://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions/10812#10812 –