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

  • SEARCH
  • Home
  • 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 3223168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:04:32+00:00 2026-05-17T16:04:32+00:00

Hey folks, beneath is a piece of code i used for a school assignment.

  • 0

Hey folks, beneath is a piece of code i used for a school assignment.
Whenever I enter a word, with an O in it (which is a capital o), it fails!
Whenever there is one or more capital O’s in this program, it returns false and logs : sentence not a palindrome.

A palindrome, for the people that dont know what a palindrome is, is a word that is the same read left from right, and backwards. (e.g. lol, kayak, reviver etc)
I found this bug when trying to check the ‘oldest’ palindrome ever found: SATOR AREPO TENET OPERA ROTAS.

When I change all the capital o’s to lowercase o’s, it works, and returns true.
Let me state clearly, with this piece of code ALL sentences/words with capital O’s return false. A single capital o is enough to fail this program.

-(BOOL)testForPalindrome:(NSString *)s position:(NSInteger)pos {
    NSString *string = s;
    NSInteger position = pos;
    NSInteger stringLength = [string length];
    NSString *charOne = [string substringFromIndex:position];
    charOne = [charOne substringToIndex:1];

    NSString *charTwo = [string substringFromIndex:(stringLength - 1 - position)];
    charTwo = [charTwo substringToIndex:1];
    if(position > (stringLength / 2)) {
        NSString *printableString = [NSString stringWithFormat:@"De following word or sentence is a palindrome: \n\n%@", string];
        NSLog(@"%@ is a palindrome.", string);
        [textField setStringValue:printableString];
        return YES;
    }
    if(charOne != charTwo) {
        NSLog(@"%@, %@", charOne, charTwo);
        NSLog(@"%i", position);
        NSLog(@"%@ is not a palindrome.", string);
        return NO;
    }
    return [self testForPalindrome:string position:position+1]; 
}

So, is this some weird bug in Cocoa?
Or am I missing something?

  • B
  • 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-05-17T16:04:33+00:00Added an answer on May 17, 2026 at 4:04 pm

    This of course is not a bug in Cocoa, as you probably knew deep down inside.

    Your compare method is causing this ‘bug in Cocoa’, you’re comparing the addresses of charOne and charTwo. Instead you should compare the contents of the string with the isEqualToString message.

    Use:

    if(![charOne isEqualToString:charTwo]) {
    

    Instead of:

    if(charOne != charTwo) {
    

    Edit: tested it in a test project and can confirm this is the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, in the Programming Pearls book, there is a source code for setting, clearing
Hey folks, I have a question which feels stupid but I can't quite say
Hey folks, ok so this is my problem, I need to display HTML code
Hey folks - I'm writing a pretty simple iPhone application. The data comes from
Hey Folks i am trying to compile this C++ program: #include <stdio.h> #include <string.h>
Hey folks, hoping you can help me get started with IronRuby. I have several
Hey folks, I've got an ASP.NET web site project that for some reason is
Hey folks. I have a client who's old website was called toastkid.com. I set
Hey folks. I'm looking for the best way to do something simple in symfony.
Hey folks, every once in a while I have the need to automate data

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.