EncodeURLComponent

In my desktop app I upload a file to a web service and pass the filename in the URL. I use EncodeURLComponent to remove the spaces and non-conforming characters from the filename. There is no EncodeURLComponent method in iOS but…is there another way to achieve this in iOS?

Declare Function CFURLCreateStringByAddingPercentEscapes lib “Foundation” (allocator as Ptr, origString as CFStringRef , charactersToLeaveUnescaped as CFStringRef , legalURLCharactersToBeEscaped as cfStringRef,encoding as uint32) as CFStringRef

example:
myText as text is you component to encode:

dim myEncodedComponent as text
myEncodedComponent =CFURLCreateStringByAddingPercentEscapes(nil,x,nil,nil,&h08000100)
where &h08000100 if for utf-8 encoding

The inverse:
Declare Function CFURLCreateStringByReplacingPercentEscapesUsingEncoding lib “Foundation” (allocator as Ptr, origString as CFStringRef , charactersToLeaveEscaped as CFStringRef ,encoding as uint32) as CFStringRef

example:
dim myOriginalText as Text
myOriginalText =CFURLCreateStringByReplacingPercentEscapesUsingEncoding(nil, myEncodedComponent,nil,&h08000100)

Thank you Antonio. :slight_smile: