简体   繁体   中英

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.

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

请参见-floatValue -componentsSeparatedByString:-floatValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM