Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:01:12+00:00 2026-06-12T06:01:12+00:00

Possible Duplicate: Case insensitive string comparison in C++ I’ve written some code for a

  • 0

Possible Duplicate:
Case insensitive string comparison in C++

I’ve written some code for a c++ to compare two strings for equality. What I’d like is a proofreading. I’m planning on using this for more programs in the future, so it’s important that this function do its job well. Does this function look like one that will be reusable, portable, etc.? Is there a more ‘up-to-date’ method of doing this? I used a c library but this is a c++ program, is that taboo?

Thanks, JH.

//function to compare two strings regardless of case 
//-- returns true if the two strings are equal
//-- returns false if
//  --the strings are unequal
//  --one of the strings is longer than 255 chars
bool isEqual(string str1, string str2){

  if(str1.length()!=str2.length())  //the strings are different lengths,
    return false;               //they can't be equal
  if((str1.length()>255) || (str2.length()>255))
    return false;

  char * cstr1 = new char [str1.length()+1];
  strcpy (cstr1, str1.c_str());
  char * cstr2 = new char [str2.length()+1];
  strcpy (cstr2, str2.c_str());

  for(int i=0; i<str1.length()+1; i++){
    if(toupper(cstr1[i]) != toupper(cstr2[i]))
      return false;
  }

  return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:01:13+00:00Added an answer on June 12, 2026 at 6:01 am

    You should rename the function to isEqual_CaseInsensitive or something to have a name that matches what the function does.
    You should pass the strings by reference to avoid a copy
    You don’t need to create a copy of the strings to compare them

        bool isEqual_CaseInsensitive(const string& a, const string& b)
        {
                return a.size() == b.size() &&
                    std::equal(a.begin(), a.end(), b.begin(), [](char cA, char cB) {
                            return toupper(cA) == toupper(cB);
                       });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to compare case insensitive two strings in php I need to
Possible Duplicate: How do I do a case insensitive string comparison in Python? I
Possible Duplicate: Case insensitive string comparison in C++ C++ count and map How to
Possible Duplicate: CSS selector case insensitive for attributes The here below code checks if
Possible Duplicate: concatenation of two string literals Case 1 hello world (NO ERROR) Case
Possible Duplicate: Case insensitive contains(string) With Contains() method of String class a substring can
Possible Duplicate: Is there an alternative to string.Replace that is case-insensitive? I'm looking for
Possible Duplicate: Case insensitive std::string.find() I want to make use of the std::string::find() method
Possible Duplicate: Convert string to Pascal Case (aka UpperCamelCase) in Javascript I'm doing some
Possible Duplicate: Case insensitive string replacement in JavaScript? I am trying to highlight part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.