Groovy - How to compare the string?

后端 未结 7 1650
醉话见心
醉话见心 2021-02-04 23:03

how to compare the string which is passed as a parameter

the following method is not working.

 String str = \"saveMe\"

 compareString(str)

 def         


        
7条回答
  •  孤独总比滥情好
    2021-02-04 23:40

    If you don't want to check on upper or lowercases you can use the following method.

    String str = "India" 
    compareString(str) 
    
    def compareString(String str){ 
      def str2 = "india" 
      if( str2.toUpperCase() == str.toUpperCase() ) { 
        println "same" 
      }else{ 
        println "not same" 
      } 
    }
    

    So now if you change str to "iNdIa" it'll still work, so you lower the chance that you make a typo.

提交回复
热议问题