AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

How to use Unicode text in streams?

Ein Thema von WojTec · begonnen am 12. Okt 2010 · letzter Beitrag vom 12. Okt 2010
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

How to use Unicode text in streams?

  Alt 12. Okt 2010, 11:25
Delphi-Version: 2010
How to use Unicode strings in streams? I need to save strings in binary stream - for this I'm using TStringStream, but string are stored as ASCII.

Delphi-Quellcode:
var
  S: TStringStream;
begin
  S := TStringStream.Create;
  S.Encoding.UTF8;
  S.WriteString('');
  S.SaveToFile('C:\0.txt');
  S.Free;

  S := TStringStream.Create;
  S.Encoding.UTF8;
  S.LoadFromFile('C:\0.txt');
  Caption := S.DataString;
  S.Free;
end;
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: How to use Unicode text in streams?

  Alt 12. Okt 2010, 11:39
Delphi-Quellcode:
  Encoding := TEncoding.Unicode;
  S := TStringStream.Create('',Encoding);
Delphi-Quellcode:
  ss := '';
  S := TStringStream.Create;
  S.Encoding.Unicode;
  S.WriteString(ss);
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)

Geändert von Bummi (12. Okt 2010 um 11:44 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#3

AW: How to use Unicode text in streams?

  Alt 12. Okt 2010, 12:30
Zitat:
S.Encoding.Unicode;
Falsch, da man den Wert ja setzen und nicht ein Property davon auslesen will,
also theoretisch wäre es so richtig
S.Encoding := TEncoding.Unicode; .


Aber leider ist .Encoding readonly, also geht es nur im Contructor.
Delphi-Quellcode:
S := TStringStream.Create('', TEncoding.UTF8);

// oder

S := TStringStream.Create('', TEncoding.UTF8);
S.WriteString('');
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (12. Okt 2010 um 12:37 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#4

Re: How to use Unicode text in streams?

  Alt 12. Okt 2010, 12:41
Encoding property is read only, so I did'n knew how to use it, I don't saw encoding parameter in constructor. Now working very well, thanks guys
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz