开发者

How to get text in a NSString that is in between two characters/words?

开发者 https://www.devze.com 2023-02-16 03:43 出处:网络
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

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消