Ask coding questions

← Back to all posts
How can I check if two strings are the same case insensitive
L0k3d20uz4 (1)

So I am making a program that checks to see if words are palindromes. I have a word, have reversed the word, but now I need to check if the two strings are the same not worrying about the case of the letters. I have tried using boost/algorithm/string.hpp as suggested by an answer on stackOverflow, but I'm not sure if I'm using it correctly. It does not give me any errors, but instead of displaying true or false, it displays 1 or 0. Please tell me what I'm doing wrong or if there is a better way to do this.

Answered by Bookie0 (6395) [earned 5 cycles]
View Answer
Bookie0 (6395)

Well 1 is true, and 0 is false, so you could check what the number is and with conditionals determine whether it's a palindrome or not.

Also if you get stuck, you can check this W3 Schools page out for how to check if a string is a pallindrome.

Good luck! :D

Coder100 (18925)

case insensitivity is very very very very not straightforward

#include <ctype.h>
#include <string>

std::string to_lower(std::string s) {
  std::string out = "";
  for (char c : s) {
    s += tolower(c);

  return out;
firefish (950)

not straightforward

@Coder100 Good question... what is the opposite of straightforward? is it crookedbackward? oh wait you just say difficult don't you