• 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: Problems instantiating an URL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems instantiating an URL


  • Subject: Re: Problems instantiating an URL
  • From: Tito Ciuro <email@hidden>
  • Date: Sat, 7 Oct 2006 19:27:07 -0700

Bingo! :-)

Thanks Ryan! It works fine now.

-- Tito

On Oct 7, 2006, at 7:21 PM, Ryan Britton wrote:

Why not use stringByAddingPerfectEscapesUsingEncoding: rather than your own replacing code?

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/ instm/NSString/stringByAddingPercentEscapesUsingEncoding:

That will ensure the string is valid for a URL.

On Oct 7, 2006, at 6:11 PM, Tito Ciuro wrote:

Hello,

I fail to see why instantiating the following URL fails. Here's the code:

NSMutableString * googleAddress = [NSMutableString stringWithString:[self stringValue]];

// Prepare the address in a format that Google understands...
[googleAddress replaceOccurrencesOfString:@"\n" withString:@"+" options:nil range:NSMakeRange(0, [googleAddress length])];
[googleAddress replaceOccurrencesOfString:@" " withString:@"+" options:nil range:NSMakeRange(0, [googleAddress length])];


        NSLog(@"%@", googleAddress);
        NSURL *url = [NSURL URLWithString:googleAddress];
        NSLog(@"%@", url);
        [[NSWorkspace sharedWorkspace]openURL:url];

This is the output:

2006-10-07 18:07:21.563 Test[14980:117] http://maps.google.com/ maps?q=4720+Forbes+Avenue,Suite+420+Pittsburgh?+Pennsylvania?+15213 +United+States
2006-10-07 18:07:21.564 Test[14980:117] (null)


If you paste the URL above in Google maps, it works fine. However, URLWithString: returns nil. Any idea why?

Thanks in advance,

-- Tito
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Problems instantiating an URL (From: Tito Ciuro <email@hidden>)
 >Re: Problems instantiating an URL (From: Ryan Britton <email@hidden>)

  • Prev by Date: Re: Problems instantiating an URL
  • Next by Date: filterPredicate binding following relationship in keypath
  • Previous by thread: Re: Problems instantiating an URL
  • Next by thread: filterPredicate binding following relationship in keypath
  • Index(es):
    • Date
    • Thread