• 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: Satoshi Matsumoto <email@hidden>
  • Date: Wed, 10 Mar 2004 16:50:56 +0900

Dear Louis,

Thank you for your kind information. It's very helpful.

But in following case, where absolute URLs are outside of base URL directory

baseURLString = @"http://www.base.com/url/";
absoluteURLString = @"http://www.base.com/img/image.jepg";

The result relativeURL should be @"../img/image.jepg"

I am going to write a method that can handle above cases...

Satoshi

on 04.3.10 4:24 PM, Louis C. Sacha at email@hidden wrote:

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


References: 
 >Re: Conversion from an absolute URL to relative (From: "Louis C. Sacha" <email@hidden>)

  • Prev by Date: Re: Conversion from an absolute URL to relative
  • Next by Date: HElp with NSResponder
  • Previous by thread: Re: Conversion from an absolute URL to relative
  • Next by thread: Re: Conversion from an absolute URL to relative
  • Index(es):
    • Date
    • Thread