Autor Beitrag
UliTs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP*, Win 7
xBase++, Delphi 10.3
BeitragVerfasst: Mi 25.09.19 11:16 
Hallo allerseits.

Ich lese eine CSV-Datei, die das UTF8-Format benutzt, ein und konvertiere sie anschließend nach ANSI:

ausblenden Quelltext
1:
2:
CSVDatei.LoadFromFile( OpenDialogCSVDatei.FileName );
for I := 0 to CSVDatei.Count-1 do CSVDatei.Strings[I] := UTF8ToString(CSVDatei.Strings[I]);

Gibt es eine elegantere Lösung bzw. kann man dies direkt beim Aufruf von LoadFromFile machen?
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 25.09.19 11:42 
Was ist "CSVDatei"? Wenn das zum Beispiel eine TStringList ist, kannst Du das Encoding direkt bei LoadFromFile angeben.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)

Für diesen Beitrag haben gedankt: UliTs
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 762
Erhaltene Danke: 127



BeitragVerfasst: Mi 25.09.19 18:20 
Meinst Du so etwas (wenn CSVDatei eine Listbox ist)?

ausblenden Delphi-Quelltext
1:
CSVDatei.Items.Text:= UTF8ToString(CSVDatei.Items.Text);					

ub60

Für diesen Beitrag haben gedankt: UliTs
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 25.09.19 19:46 
Ne, wohl eher so:
ausblenden Delphi-Quelltext
1:
CSVDatei.LoadFromFile( OpenDialogCSVDatei.FileName, TEncoding.UTF8);					


Das geht aber nur mit neueren Delphi-Versionen, nicht mit Delphi 6, was du im Profil angegeben hast. Ob es da noch was eleganteres gibt, weiß ich nicht. Da war das String-Handling Ansi/Unicode/UTF8 (ich vermische da jetzt die Begriffe etwas), ja auch noch ganz anders mit der "Nicht-Unicode-fähigen" VCL ... :?

_________________
We are, we were and will not be.

Für diesen Beitrag haben gedankt: UliTs
UliTs Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP*, Win 7
xBase++, Delphi 10.3
BeitragVerfasst: Mi 25.09.19 20:28 
Vielen Dank für die schnelle Hilfe! Ich habe gar nicht damit gerechnet :-) .

Ich habe inzwischen eine aktuelle Delphi-Version: 10.3. -> Muss noch meine Signatur anpassen :-) .

Gausi, genau so etwas habe ich gesucht, aber übersehen.

P.S.
Ja, war eine StringList.