Solved

Utf8 encode

Posted on 2013-11-21
2
567 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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

22 Experts available now in Live!

Get 1:1 Help Now