How do I Do A Case-Insensitive String Comparison?

In this tutorial, we will learn How to do a Case-Insensitive String Comparison, which we can perform by simply converting both the strings that we want to compare in either in lower case or uppercase so that every character in the string has the same ASCII  values and in programming, we compare the character using it’s ASCII values.

Where ASCII values of each character are different even the ASCII value of lower case a is different from upper case A so to compare both we simply convert all of them in a single platform so that they will have the same range of ASCII values.



Case-Insensitive means in a string when we have both lower case and upper case characters involved and we can say in a single string there might be upper case and another string is in lower case both alphabets there in that string are the same that were there in previous one.

String string1 = "Hello World";
String string2 = "hello world";

if (string1. equals Ignore Case( string2)) {
    System. out. println(" The strings are equal");

Here string1 has both upper case and lower case characters where as string 2 have all lower case characters so irrespective of both the strings have the same alphabet but on comparing both they will not be the same as their ASCII values of each are different so the answer might barry.

To avoid such complications we can simply convert whole strings of both strings into either of the form lower or upper to make their ASCII values comparable.


To learn more about How To Do A Case-Insensitive String Comparison visit: Case insensitive comparison.

To learn more about python visit What Is The Difference Between re. search() and re.match() Functions? In Python. and to learn more about concepts, along with solving the problems related to python programming langiges.

To lear  more about different programming languages and tutorials on the problems faced by students visit. beta python programming languages Solutions.

Leave a Comment

%d bloggers like this: