Jos käytät vanhempaa Delphiä ( esim. Delphi 5, Delphi 4, Delphi 3, Delphi 2, ehkä myös Delphi 6 ) ja tarvitset muunnosta UNICODE UTF-8 ja ANSI String ja TStrings tai TStringlist -tyyppien välillä, katsopa tänne:
http://tinyurl.com/UTF8-Delphi
tai
http://preview.tinyurl.com/UTF8-Delphi
JOS tinyurl -linkki vanhenee käytön puutteen takia, koko URL on:
http://www.koders.com/delphi/fid77D937B228CC8CFB3D81DCAD3BB58DA174055686.aspx
UTF-8 hallintaan !
ps.
kannattaa määritellä ko. Unitin alkuun:
type
UTF8String = type AnsiString;
Vihje: UTF-8 ja vanhat Delphi -versiot
2
228
Vastaukset
- Delphiguru
vielä kannattaa muokata unitin alkuosa tällaiseksi:
unit UTF8;
{-----------------------------------------------------------------------------
Unit Name: UTF8
extracted from LibXmlParser
Author: Stefan Heymann ([email protected])
Purpose: UTF8 conversion routines (those included in Kylix don't work)
Version: v. 1.0
Licence: "Destructor.de Source code Licence" (DSL)
The official site to get this parser is http://www.destructor.de/
Usage and Distribution of this Source Code is ruled by the
"Destructor.de Source code Licence" (DSL) which comes with this file or
can be downloaded at http://www.destructor.de/
IN SHORT: Usage and distribution of this source code is free.
You use it completely on your own risk
-----------------------------------------------------------------------------}
interface
uses
Classes;
type
UTF8String = type AnsiString;
function Utf8ToAnsi(Source: UTF8String; UnknownChar: char = ' '): AnsiString;
function AnsiToUtf8(Source: AnsiString): UTF8String;
procedure ConvertStringList_UTF8ToAnsi(SL:TStrings);
procedure ConvertStringList_AnsiToUTF8(SL:TStrings);
implementation
procedure ConvertStringList_UTF8ToAnsi(SL:TStrings);
var
i : Integer;
begin
for i := 0 to SL.Count-1 do begin
SL[i] := UTF8ToAnsi(SL[i]);
end;
end;
procedure ConvertStringList_AnsiToUTF8(SL:TStrings);
var
i : Integer;
begin
for i := 0 to SL.Count-1 do begin
SL[i] := AnsiToUTF8(SL[i]);
end;
end;
const
// --- Character Translation Table for Unicode Win-1252
//----- muokkausten loppu ------ Delphiguru
.. sekä muuttaa myös myöhemmin koodissa vastaavat 2 funktiomäärittelyä:
function AnsiToUtf8(Source: AnsiString): UTF8String;
(* Converts the given Windows ANSI (Win1252) String to UTF-8. *)
SEKÄ MYÖS:
function Utf8ToAnsi(Source: UTF8String; UnknownChar: char = ' '): AnsiString;
(* Converts the given UTF-8 String to Windows ANSI (Win-1252).
If a character can not be converted, the "UnknownChar" is inserted. *)
Ketjusta on poistettu 0 sääntöjenvastaista viestiä.
Luetuimmat keskustelut
- 406953
- 323918
- 453300
- 402909
- 162672
- 372228
- 162176
- 412123
Voi ei! Jari Sillanpää heitti keikan Helsingissä - Hämmästyttävä hetki lavalla...
Ex-tangokuningas on parhaillaan konserttikiertueella. Hän esiintyi Savoy teatterissa äitienpäivänä. Sillanpää jakoi kons482057- 392000