Solved

Utf8 encode

Posted on 2013-11-21
2
603 Views
Last Modified: 2013-11-22
Hi Experts,

Please I need help to convert string to utf8.

eg.:

cabeça - > cabe%C3%A7a
zé -> z%C3%A9
avó -> %C3%B3

I need to store the converted value in a variable.
I tried to use utf8encode(variable) but did not work.

var
  texto:string;
begin
   texto:=utf8encode('cabeça');
   showmessage(texto);
end;

But the result was "cabeça" and not "cabe%C3%A7a" as expected.

Please, some help.
Thanks
Alexandre
0
Comment
Question by:alpires
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:livestuff
ID: 39667564
UTF8Encode Converts a WideString value to a UTF8 string.



change your string var to WideString

http://docwiki.embarcadero.com/RADStudio/XE5/en/UTF-8_Conversion_Routines
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39667611
No, this is not native utf8 converting. This strings is for web... I'm right?
You need string to url encoding. Some examples here:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_24870513.html
http://en.wikipedia.org/wiki/Percent-encoding#Current_standard

...but here is windows api function in wininet:
uses WinInet;
...
function EncodeUri(aSrc: String): String;
var
  Size: Cardinal;
  Buff: String;
begin
  Size := MAX_PATH;
  SetLength(Buff, Size);
  if not InternetCanonicalizeUrl(PChar(aSrc), PChar(Buff), Size, 0) then
    Size := 0;
  SetLength(Buff, Size);
  Result := Buff;
end;

Open in new window

0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question