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 989597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:49:07+00:00 2026-05-16T05:49:07+00:00

I’m trying to compare the equality of two multi-line strings. I’m getting one of

  • 0

I’m trying to compare the equality of two multi-line strings. I’m getting one of the strings from a web service, and the other I’m getting from iTunes via the Scripting Bridge. The strings from the web service are eventually transferred to iTunes, so if I do that and then re-compare the strings, ideally they’d be identical.

However, when comparing strings like this, it seems that isEqualToString: always returns non-equality. I’m testing this by testing equality of a string from iTunes that originally came from the web service, and a string directly from the web service.

Logging both strings to the Console produces output from both strings that appears identical. Logging the lengths of the strings produce identical lengths.

I’ve also tried comparing the strings using some other methods. For example, I converted them to ASCII strings to make sure it wasn’t some Unicode issue:

        NSData *iTunesStringData = [[self iTunesString] dataUsingEncoding:NSASCIIStringEncoding
                                                     allowLossyConversion:YES];
        NSData *webServiceStringData = [[self webServiceString] dataUsingEncoding:NSASCIIStringEncoding
                                                     allowLossyConversion:YES];


        NSString *newiTunesString = [[[NSString alloc] initWithData:iTunesStringData encoding:NSASCIIStringEncoding] autorelease];
        NSString *newWebServiceString = [[[NSString alloc] initWithData:webServiceStringData encoding:NSASCIIStringEncoding] autorelease];

        BOOL result = [newiTunesString isEqualToString:newWebServiceString];

Same problem, not equal. I’ve tried comparing just the first character:

        NSComparisonResult result = [newiTunesString compare:newWebServiceString
                                                            options:NSLiteralSearch
                                                              range:NSMakeRange(0,1)
                                                             locale:[NSLocale currentLocale]];

Does not return NSOrderedSame. I’ve logged these first characters to the Console and they seem identical. I also considered differences in carriage returns, and tried replacing @”\r” with @”” in both strings before comparing, which doesn’t work (and besides, that shouldn’t affect equality of just the first character). I don’t want to remove @”\n” characters because I want to preserve the multiple lines.

What’s going on? Any other ideas?

  • 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-16T05:49:08+00:00Added an answer on May 16, 2026 at 5:49 am

    It turns out this problem was related to line endings. But since I’m comparing multi-line strings, I didn’t want to completely strip out the newlines. I normalized the line endings like so:

            NSString *normalizediTunesString = [[[self iTunesString] componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@"\n"];
            NSString *normalizedWebServiceString = [[[self webServiceString] componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@"\n"];
    

    Then, comparing the strings via compare: worked as expected.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.