Questions tagged [ignore-case]

A method that ignores case when comparing two strings.

There will often be times that you will need to compare two strings by ignoring the case of the string. There are many ways to accomplish this in programming more often than not by converting both strings to lower or upper case characters. Some languages have built in ways of doing this, others will require a few extra steps.

For example, in Java the String class contains a method called equalsIgnoreCase. The Java 7 API description for equalsIgnoreCase:

Compares this String to another String, ignoring case considerations.

An example of how to use equalsIgnoreCase in Java that will return false:

String x = "Hello";
String y = "World";

if(x.equalsIgnoreCase(y)) {
    return true;
 } else {
    return false;
}

To accomplish the same thing in PHP you could do the following:

<?php
  $var1 = "Hello";
  $var2 = "hello";

  if (strcasecmp($var1, $var2) == 0) {
     echo '$var1 is equal to $var2 in a case-insensitive string comparison';
  }
?>

The above example was taken from the PHP documentation.

94 questions
192
votes
9 answers

SQL- Ignore case while searching for a string

I have the following data in a Table PriceOrderShipped PriceOrderShippedInbound PriceOrderShippedOutbound In SQL I need to write a query which searches for a string in a table. While searching for a string it should ignore case. For the below…
shockwave
  • 3,074
  • 9
  • 35
  • 60
96
votes
12 answers

Case Insensitive String Comparison in C

I have two postcodes char* that I want to compare, ignoring case. Is there a function to do this? Or do I have to loop through each use the tolower function and then do the comparison? Any idea how this function will react with numbers in the…
bond425
  • 1,077
  • 1
  • 7
  • 12
41
votes
10 answers

How to ignore case in String.replace

string sentence = "We know it contains 'camel' word."; // Camel can be in different cases: string s1 = "CAMEL"; string s2 = "CaMEL"; string s3 = "CAMeL"; // ... string s4 = "Camel"; // ... string s5 = "camel"; How to replace 'camel' in sentence…
Xaqron
  • 29,931
  • 42
  • 140
  • 205
35
votes
6 answers

Java Set equality ignore case

I want to check if all elements of two sets of String are equal by ignoring the letter's cases. Set set1 ; Set set2 ; . . . if(set1.equals(set2)){ //all elements of set1 are equal to set2 //dosomething } else{ //do something…
nafas
  • 5,283
  • 3
  • 29
  • 57
21
votes
5 answers

Why is String.equalsIgnoreCase is so slow

I encountered a question in interview to write a method to check for similar words irrespective of character cases. I answered it by using the difference of ASCII value for each pair of characters. But at home, when I went through the actual…
53by97
  • 425
  • 3
  • 17
14
votes
2 answers

How to get gVim's vimdiff to ignore case?

I am trying to compare two assembly files where one was written all caps and the other in lowercase. Many lines are identical up to case and whitespace. I tried the following, while two buffers in diff mode: :set diffopt+=icase :set…
ysap
  • 7,723
  • 7
  • 59
  • 122
14
votes
2 answers

Git on windows: Can't switch branch after renaming a file (only changed case)

I'm working with git on windows, and I have a file in my repo, lets say "foo.txt". Today I wanted to rename this file to "Foo.txt" (uppercase). As suggested in this SO question, I used git mv -f foo.txt Foo.txt, which produced the desired result. I…
avivr
  • 1,393
  • 15
  • 28
13
votes
3 answers

How can I ignore case in a regex?

I have an ASP.NET RegularExpressionValidator that checks file extensions. Is there a quick way I can tell it to ignore the case of the extension without having to explicitly add the upper case variants to my validation…
flesh
  • 23,725
  • 24
  • 80
  • 97
12
votes
10 answers

How to use StringComparison for strings in C#?

string body = Selenium.GetBodyText(); if (body.Contains("software", StringComparison.CurrentCultureIgnoreCase)) { //do something } I get a string does not contain a definition for Contains message when I do the above. What am I doing wrong…
Maya
  • 7,053
  • 11
  • 42
  • 53
12
votes
2 answers

"(?i)" does not work with accents

I have a Java method that looks for a word inside a phrase ignoring the case sensitivity of the word, and if it finds the word then it removes it from the phrase. The word and the phrase can be anything. They're variant. Here is my code : private…
Brad
  • 4,457
  • 10
  • 56
  • 93
10
votes
3 answers

How to return a default boolean value in java streams if element not found?

I want to determine if a given string matches - ignoring case - one of the elements in a List. I'm trying to achieve this with Java 8 streams. Here's my attempt using .orElse(false): public static boolean listContainsTestWord(List
membersound
  • 81,582
  • 193
  • 585
  • 1,120
9
votes
2 answers

Ignore case using boost::regex_search

How do you use boost::regex_search with the ignore case flags or constants in C++? Please post an easy example. Thanks!
arturgspb
  • 1,004
  • 1
  • 12
  • 19
9
votes
3 answers

C# compare string ignoreCase

Within this test method I need to compare the strings of user3 while ignoring case sensitivity. I'm thinking I should use CultureInfo.InvariantCulture to ignoreCase. Is this the best way to accomplish this, or is there a better way? …
user216672
  • 151
  • 3
  • 5
  • 14
7
votes
3 answers

How to set ignorecase flag for part of regular expression in Python?

Is it possible to implement in Python something like this simple one: #!/usr/bin/perl my $a = 'Use HELLO1 code'; if($a =~ /(?i:use)\s+([A-Z0-9]+)\s+(?i:code)/){ print "$1\n"; } Letters of token in the middle of string are always capital.…
Dmitry Nedbaylo
  • 2,254
  • 1
  • 20
  • 20
6
votes
6 answers

Ignore case while comparing string with keyvalue in the hashmap

I am trying to check if my hashmap key set contains the string 'buffSB.toString()'. But I wanted to compare ignoring case (upper or lower). static StringBuilder buffSB = new StringBuilder(); buffSB.append(alphabet); Map pref = …
Leyon Gudinho
  • 91
  • 2
  • 11
1
2 3 4 5 6 7