Solved

Utf8 encode

Posted on 2013-11-21
2
561 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
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 25

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now