开发者

Parsing Web URL in iPhone Development

I am trying to parse a HTML string in a iPhone app.

Example: The URL is http://www.apple.com/developer

I want to delete the "developer" part so all I have will be http://www.apple.com

How coul开发者_如何学编程d I do this?


You can also bring it in to an NSURL and get the parts you want:

NSURL *url = [NSURL URLWithString:@"http://www.apple.com/developer"];
[url host]; // @"www.apple.com"
[url scheme]; // @"http"


You can search for the third slash in the string and then substring it to get the part you want


Have you considered the NSUrl method URLByDeletingLastPathComponent or the method pathComponents?

URLByDeletingLastPathComponent

Returns a new URL made by deleting the last path component from the original URL.

pathComponents

Returns the individual path components of a file URL in an array.

Here is a good tutorial/example on NSURL methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜