0SX
0SX

Reputation: 1292

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, Thanks.

Upvotes: 0

Views: 769

Answers (3)

NSResponder
NSResponder

Reputation: 16861

See -componentsSeparatedByString: and -floatValue

Upvotes: 1

hoha
hoha

Reputation: 4428

XML parser if input is XHTML. Regular expressions otherwise (take a look at NSRegularExpression).

Upvotes: 1

Erik B
Erik B

Reputation: 42554

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

Upvotes: 1

Related Questions