Resolved hpple and string encoding

Discussion in 'iOS Programming' started by Warren93, Aug 15, 2013.

  1. Warren93, Aug 15, 2013
    Last edited: Aug 16, 2013

    Warren93 macrumors newbie

    Aug 15, 2013
    I've been following a tutorial ( about parsing html in iOS with Hpple, and I have noticed that using hpple to get a text node from its parent html element returns a string that is a different length than it is if I just copy/paste the text into xcode. For example, this gives a string with a length of 69:

    NSString *str = [[element firstChild] content];

    where the element looks like this on the site:
    <a href="/home/programs/1373">A Conversation Between Friends: Language, Love, and The Writing Life</a>

    ...whereas copy/pasting the text into the code:

    NSString *str = @"A Conversation Between Friends: Language, Love, and The Writing Life"; a string with length 68 (or at least these are the result I get with NSString's length function). So from this I conclude that the returned string and string I created from copying and pasting must be encoded differently or something. Is this a correct assumption?

    If needed, I can provide more of the code for context. Thanks in advance for any help.
  2. ArtOfWarfare macrumors G3


    Nov 26, 2007
    I wouldn't suspect string encoding. Perhaps there's a Whitespace character that you didn't copy, or that the function you used added?

    I've never tried this with NSStrings, only C++/C strings, but maybe if you check the debugger it can tell you what character is at each position of each string.
  3. Warren93 thread starter macrumors newbie

    Aug 15, 2013
    You are correct; I seem to have lost a whitespace character when copy/pasting. Thanks for your help!

Share This Page