Encoding text to pass to php via curl

Hi,

I use the following code to encode the text that is passed via curl to PHP:

set myString to NSString’s stringWithString_(myText)
set encodedText to myString’s stringByAddingPercentEscapesUsingEncoding_(current application’s NSUTF8StringEncoding)

I discovered reading logs that if a file contains the & character like “John & Smith.doc” the log is incomplete.
I need to encode also the “&” char?
What cocoa cooamd can be used? The variable encodedText is bigger.
I can use the fast “set applescript’s text idem delimiters to …” but If I would like to use cocoa command what is the best?

Rufus

Hi,

the best Cocoa method for that purpose is NSMutableString’s replaceOccurrencesOfString:withString:options:range:, but it can’t be used in ASOC because it requires the Foundation Function NSMakeRange(), which is not available in ASOC.

A second way is to create a NSString category for escaping the characters with the CoreFoundation CFURLCreateStringByAddingPercentEscapes() function, which is much more flexible than the Cocoa equivalent.

Finally I recommend to use text item delimiters.

You don’t need NSMakeRange() – you can just pass an AS record (or list). Like this:

{|location|:0, |length|:0}

Thanks Shane, I always forget this