相关疑难解决方法(0)

我如何在Ruby中进行字符串比较?

我使用以下代码来比较字符串,但它总是把我带到else.为什么?

print("Enter your state abbreviation: ")
state_abbreviation = gets
if state_abbreviation.upcase == "NC"
  puts("North Carolina")
elsif state_abbreviation.upcase == "SC"
  puts("Sourth Carolina")
elsif state_abbreviation.upcase == "GA"
  puts("Georgia")
elsif state_abbreviation.upcase == "FL"
  puts("Florida")
elsif state_abbreviation.upcase == "AL"
  puts("Alabama")
else
  puts("You have enter wrong abbreviation")
end
Run Code Online (Sandbox Code Playgroud)

我也试过,.eql?("string")但我得到了相同的结果.

ruby

7
推荐指数
3
解决办法
4万
查看次数

标签 统计

ruby ×1