When I use if/else
I want the if to be case-insensitive. So instead of having to type "What's Up"
, "what's up"
, "What's up"
, "What's UP"
, et cetera, I can make it case insensitive and only use one variation of "what's up"
.
Asked
Active
Viewed 100 times
0

Yu Hao
- 119,891
- 44
- 235
- 294
-
1Which language? Give an example. What have you tried so far? – m02ph3u5 Aug 23 '15 at 17:47
-
Add tags related to the language and technology too. – Glauco Neves Aug 23 '15 at 18:05
-
1 python 2ive tried to make all possible ways to word the if in this case what's up in caps @m02ph3u5 – user5257727 Aug 23 '15 at 18:06
-
Make everything lower case or uppercase and compare or use a native case-insensitive function for camparison (if available). – m02ph3u5 Aug 23 '15 at 18:14
2 Answers
2
Convert the string to lower case (or upper case), and then compare:
>>> s = "What's Up"
>>> s.lower() == "What's up".lower()
True

Yu Hao
- 119,891
- 44
- 235
- 294
0
In any language, just make the text entered to be lowercase first and then compare it in the if/else block.
In java, you can store the value in a string and use the equalsIgnoreCase() method to compare values in if/else block.
Go to this link: equalsIgnoreCase
Search for equalsIgnoreCase() method on this page
Check below link:
case insensitive String comparison for Python
Hope this helps

Saurabh Nailwal
- 37
- 6