[英]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. 我正在尝试从两个特定的单词/字符之间的NSString获取值。 Here is the NSString that I'm working with:Name
这是我正在使用的NSString:名称
<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? 我试图提取样式值,在此示例中为width:80.4px怎么办? 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. 我建议使用XML解析器。 You could use
NSXMLParser
or any other parser of your choice. 您可以使用
NSXMLParser
或您选择的任何其他解析器。
Here's a comparison between xml parsers: 这是xml解析器之间的比较:
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
XML parser if input is XHTML. XML解析器(如果输入是XHTML)。 Regular expressions otherwise (take a look at
NSRegularExpression
). 否则,使用正则表达式(看看
NSRegularExpression
)。
请参见-floatValue
-componentsSeparatedByString:
和-floatValue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.