How to compare strings ignoring the case

后端 未结 5 684
名媛妹妹
名媛妹妹 2020-12-04 20:53

I want apple and Apple comparison to be true. Currently

\"Apple\" == \"Apple\"  # returns TRUE
\"Apple\" == \"APPLE\"          


        
5条回答
  •  心在旅途
    2020-12-04 21:07

    casecmp and zero? are ruby inbuilt methods. casecmp returns 0 if two strings are equal, case-insensitively and zero? checks for zero value (==0)

    str1.casecmp(str2).zero?
    

提交回复
热议问题