URL Encoding

Hi,

I need to encode a string very long to use with PHP post. I use already AS script to encode but it is slow.

Seems Cocoa have the command

CFURLCreateStringByAddingPercentEscapes_(kCFAllocatorDefault, text, null, null, kCFStringEncodingUTF8)

But I cannot get it to work.

Somebody can have suggestion?

Rufus

Hi,

CFURLCreateStringByAddingPercentEscapes() is a CoreFoundation function. You can’t call these functions with AppleScriptObjC.

Use NSString’s method stringByAddingPercentEscapesUsingEncoding: instead

Hi Stefan,

Thanks for reply. Do you have an example about how to set the call?
Example:

set encodedText to stringByAddingPercentEscapesUsingEncoding_(textToEncode)

Don’t work. I need to pass some other parameters?

Thanks in advance.

Rufus

something like this

property NSString : class "NSString"

set myString to NSString's stringWithString_("http://my domain")
set escapedString to myString's stringByAddingPercentEscapesUsingEncoding_(current application's NSUTF8StringEncoding)
--> http://my%20domain

Thanks Stefan.

Rufus