• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Conversion from an absolute URL to relative
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conversion from an absolute URL to relative


  • Subject: Re: Conversion from an absolute URL to relative
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Tue, 9 Mar 2004 23:24:19 -0800

Hello...

It would probably be easiest to work with the urls as NSStrings, using the NSURL methods that accept/return strings.

Then, you could do something like this:

NSString *baseURLString = @"http://www.base.com/url/";;
NSString *absoluteURLString = @"http://www.base.com/url/plus/other/stuff.html";;


NSString *relativeURLString;

NSRange prefix = [absoluteURLString rangeOfString:baseURLString];

if (prefix.location == 0)
{
relativeURLString = [absoluteURLString substringFromIndex:prefix.length];
}
else
{
/* base url was not found, or not at beginning of absolute url */
relativeURLString = nil;
}


For the example URL strings above, the code should result in relativeURLString containing the string @"plus/other/stuff.html", which you could put back into an NSURL if you need to using it and baseURLString.


Hope that helps,

Louis

Hi,

Are there any method in Cocoa to convert an absolute URL to a relative URL
with a given base URL?

Satoshi,
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Conversion from an absolute URL to relative
      • From: Satoshi Matsumoto <email@hidden>
  • Prev by Date: Disappearing "e" in number formatter in IB ???
  • Next by Date: Re: Conversion from an absolute URL to relative
  • Previous by thread: Conversion from an absolute URL to relative
  • Next by thread: Re: Conversion from an absolute URL to relative
  • Index(es):
    • Date
    • Thread