Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Warren93

macrumors newbie
Original poster
Aug 15, 2013
2
0
I've been following a tutorial (http://www.raywenderlich.com/14172/how-to-parse-html-on-ios) 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";

...gives 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.
 
Last edited:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
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.
 

Warren93

macrumors newbie
Original poster
Aug 15, 2013
2
0
You are correct; I seem to have lost a whitespace character when copy/pasting. Thanks for your help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.