Delphi: function to convert a string in a url-ready one [duplicate] - delphi

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Standard URL encode function?
I need to transofrm a Delphi string (like TEdit.Caption) in a "url capable" string.
I need this because I will open google maps programmatically like in TEdit I write "High Street, Sydney"
and then i would like to open the browser at maps.google.com/maps?q=High+Street+Sidney
Is there a ready function to do this, also to parse accents?

You can add IdURI unit from Indy to your uses clause, and use TIdURI.URLEncode() method to encode a URL, and TIdURI.Decode() to decode an encoded URL to a normal string.

Related

Delphi - url encoded filename? Convert To Ansi [duplicate]

This question already has answers here:
Converting UTF8 to ANSI (ISO-8859-1) in Delphi
(2 answers)
Closed 3 years ago.
I have spent most of the day looking for a solution but i can't figure it out, so i thought i'd ask the experts here.
In Outlook there is a mail message with attachments, some of the attachments have a filename with words like 'dossier pièces signée'.
We import the mail in the application but we noticed something strange with the filename of the attachment, the filename we save in the database does not match the actual filename.
After a long search i discovered the 'è' character is actually 2 characters and when i paste this in notepadd++ and show it as ansi i get 'pieÌ€ces' instead of 'pièces', so i think (but am unsure) this filename is a url encoded filename.
Since we don't do unicode or utf-8 in our database i think it would be best to store the filename after converting it to ansi, however i can't find any Delphi function that returns it like to the notepad++ format.
Does anyone have any advice please?
In delphi 2010 and after there's a Utf82Ansi internal function.
See more details in that answer here in stackoverflow: Converting UTF8 to ANSI (ISO-8859-1) in Delphi

charachter encoding in PHP Extension

I'm currently writing a PHP extension in C++ with the Zend API. Basically I make PHP_METHOD{..} wrappers around my native C++ interface methods and using "zend_parse_parameters(..)" to fetch the corresponding input arguments.
This extension contains methods which can take strings as arguments, such as a filename.
I know from http://php.net/manual/en/language.types.string.php#language.types.string.details that strings have no encoding in PHP, but still can I expect from the PHP programmer that he will use a function like "utf8_decode(..)" such that the input strings can be read by the extension correctly?
Or does the PHP Programmer expect that the extension detects the encoding from the php-script and handles strings accordingly?
Every help is highly appreciated! Thanks!
You are correct. Strings are just binary blobs in PHP. As the author of an extension. Your options:
Have the user hand your extension UTF-8: By far the best option. The user has to make the decision. Assert that the string is UTF-8 encodable and fail early.
Encode yourself: You cannot know the meaning of the string. As PHP strings are just binary blobs and have no encoding information you do not know what the intended string content is. It might as well just come from a Windows file with weird encoding and was concatenated with a complete different encoding. Worse, it might be UTF-8 encodable, but actually not UTF-8, in which way you interpret it wrongly, without the user knowing. Hence, solution 1, have the user pass UTF-8.
Alternative: Force the user to pass an input encoding.
Here is an example of the alterantive 3:
$obj = MyExtensionClass('UTF-8'); // force encoding
$obj->someMethod($inputStr); // try to convert now
The standard library uses approach 1. See json_encode as an example:

Print Unicode emoji from API response [duplicate]

This question already has an answer here:
NSString to Emoji Unicode
(1 answer)
Closed 6 years ago.
I am receiving the string #"\\U0001F603" from an API, which is the Unicode code point for the emoji 😃.
I want to display it using an UILabel's text property. If I directly set it, it shows \U0001F603 instead of the actual emoji.
How can I display the emoji at the received Unicode code point?
You have to remove first slash.
like this
label.text=#"\U0001F603";
😃.
This usually helps me
[NSString stringWithUTF8String:model.UTF8String];

Regular exception.Any character except [duplicate]

This question already has answers here:
IIS7 URL Rewriting Module Replace
(5 answers)
Closed 3 years ago.
I want
Input :www.example.com/videos/video1%2Cvideo2%2Cvideo3%2Cvideo4%2C Output:www.example.com/videos/video1,video2,video3,vide4
So i need regular expression. I tried this:^videos/[%2C](in iss url rewriting pattern). But not it is not work. It said the input data to test does not match the patter.
In your query, you mentioned it as "video", whereas in your regular expression, it is mentioned as "videos". This typo might be reason for the pattern mismatch error. Please cross check.

How to pass "&" as string in a URL? [duplicate]

This question already has answers here:
iOS: Issue with ampersand in the URL string
(6 answers)
Closed 9 years ago.
In my app I am passing a string to service which sets some data to remote database. Everything works perfect as far as I don't have "&" in my string.
I am using this to pass the parameters:
NSString *urlString = [[NSString
stringWithFormat:#"http://someservice.com/some/some_setstatus.php?status=active&name=%#",
merchant] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
My guess is when it's checking the name with the name saved in the database, it's not able to find one because of '&'.
You are unable to pass "&", as it will be treated as a delimiter for URL parameters. "&" is a reserved character and you can consider encoding "&" as a combination of allowed characters. Take a look at RFC 3986 and the answer to this question.
You need to escape the & character for url (more info: http://www.ietf.org/rfc/rfc3986.txt)
Have a look at https://github.com/tagyro/GTM/blob/master/Foundation/GTMNSString%2BURLArguments.h
This is a clone of Google Toolbox for Mac from their SVN.
I believe you need to urlEncode to the string which will properly encode any special characters. See http://www.w3schools.com/tags/ref_urlencode.asp for more information.
Regards,
Steve

Resources