How to make a string compare non case sensitive?

后端 未结 2 1376
情书的邮戳
情书的邮戳 2021-01-25 15:58

I am trying to write a code for one of those programs that responds according to your answers. I want to make it so that some of the variables are not case sensitive. For exampl

相关标签:
2条回答
  • 2021-01-25 16:26

    I think there is no way to do no case sensitive variable. From your code you want to threat answers in strings into a switch and do some action that depends on answer.

    I think the best way is to take user input a use on that string upper method from string class.

    YourString =  YourString.toUpperCase();
    
    0 讨论(0)
  • 2021-01-25 16:52

    Worth mentioning String#toLowerCase:

    name.toLowerCase().equals("me");
    

    Or simply use String#equalsIgnoreCase:

    name.equalsIgnoreCase("me");
    
    0 讨论(0)
提交回复
热议问题