开发者

split string from string

开发者 https://www.devze.com 2023-01-18 03:46 出处:网络
I have a string that contains <name>James Jones</endofname> how would i g开发者_高级运维et the name from the centre pragmatically.For this particular example, you can write [string subst

I have a string that contains <name>James Jones</endofname>

how would i g开发者_高级运维et the name from the centre pragmatically.


For this particular example, you can write [string substringWithRange:NSMakeRange(6, 11)]. For more complicated examples, you'd need to know the full extent of the language you're parsing and create a parser for it.


For some reason you've specified that you don't want xml parsing. I don't know why this is a requirement, but I'd suggest using a regex then:

^[^>]*>([^<]*)

is a somewhat crude one but it'll get you started.


You insist this is not XML parsing but your example looks an awful lot like it. So what is it?

Going on the assumption that this really is an XML document (because your example screams "yes it is!"), NSXMLParser is by far your best bet.

0

精彩评论

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