How to get text in a NSString that is in between two characters/words?
I'm trying to fetch a value from a NSString that is between two specific words/characters. Here is the NSString that I'm working with:Name
<div id="stat-2">33</div>
<div id="stat-1">Age</div>
<div id="stat-2">28</div>
<div id="stat-1">Location</div>
<div id="stat-2">190.54.5</div>
<div id="stat-1">Lot</div>
<div id="row" style="width:80.4px"> </div>
I'm trying to extract the style value which is in this example is width:80.4px How can this be done? I don't think trimming would work so I don't know what to do. Any help would be appreciated, Than开发者_StackOverflowks.
See -componentsSeparatedByString:
and -floatValue
I would suggest using an XML parser. You could use NSXMLParser
or any other parser of your choice.
Here's a comparison between xml parsers:
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
XML parser if input is XHTML. Regular expressions otherwise (take a look at NSRegularExpression
).
精彩评论