AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

$0 in stream and loading as text

Ein Thema von WojTec · begonnen am 24. Aug 2014 · letzter Beitrag vom 25. Aug 2014
Antwort Antwort
Seite 1 von 2  1 2      
WojTec

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

$0 in stream and loading as text

  Alt 24. Aug 2014, 12:33
Delphi-Version: XE5
I have sample data in stream like shown on attached image. You see many $0 inside. I want to load this stream to TStrings:

Text.LoadFromStream(Data);

Yeah, loading, but only to first $0. How to load whole data of this stream as text?

I tried also use additional string stream with encoding as Ansi or Unicode on create and load to strings from this encoded stream. The same result.
Miniaturansicht angehängter Grafiken
srestxt.png  

Geändert von WojTec (24. Aug 2014 um 12:50 Uhr)
  Mit Zitat antworten Zitat
Dejan Vu
(Gast)

n/a Beiträge
 
#2

AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 12:50
Load as binary (TFileStream) and then cast as string. But I am afraid it won't make you happy.
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 14:13
Which first $0 are you talking about?

The stream contains data with a MultiByte-Character-Set. When talking about $0 is this the value of the char or the value of the byte (half part of a char)?

Please be more precise in your questions
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

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

AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 14:32
The stream contains data with a MultiByte-Character-Set.
Encoding: UCS-2 Little Endian or UTF-16
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (24. Aug 2014 um 14:34 Uhr)
  Mit Zitat antworten Zitat
WojTec

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

Re: AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 14:34
Which first $0 are you talking about?
I'm talking about stream content (bytes). First 2 bytes are $64 (100d = Ascii(D)Ascii(d)) and $00. I'm trying load this stream as text (above code), in sample stream, after load to TStrings I have 'D''d', so looks they stop decoding text when see $0.

When I save data and load in notepad, I see characters separated with space. I want to decode whole stream as text, even if $0 bytes inside.

TStringStream.Create('', TEncoding.Unicode)
TStringStream.LoadFromStream(Source);
TStrings.LoadFromStream(TStringStream);
// result = samplestream('D''d')

Geändert von WojTec (24. Aug 2014 um 15:00 Uhr) Grund: Mistake
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#6

AW: Re: AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 14:55
Which first $0 are you talking about?
I'm talking about stream content (bytes). First 2 bytes are $64 (100d = Ascii(D)) and $00. I'm trying load this stream as text (above code), in sample stream, after load to TStrings I have 'D', so looks they stop decoding text when see $0.

When I save data and load in notepad, I see characters separated with space. I want to decode whole stream as text, even if $0 bytes inside.

TStringStream.Create('', TEncoding.Unicode)
TStringStream.LoadFromStream(Source);
TStrings.LoadFromStream(TStringStream);
// result = samplestream('D')
Oh, you are in a bigger trouble than I thought. You should have seen d and not D.
So maybe yor compiler or compter is broken ... sorry to tell that
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
WojTec

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

Re: AW: Re: AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 15:21
Oh, you are in a bigger trouble than I thought. You should have seen d and not D.
So maybe yor compiler or compter is broken ... sorry to tell that
Probably I see d, not D
Anyway don't working annd changing encoding don't want to help
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#8

AW: Re: AW: Re: AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 15:32
Oh, you are in a bigger trouble than I thought. You should have seen d and not D.
So maybe yor compiler or compter is broken ... sorry to tell that
Probably I see d, not D
Anyway don't working annd changing encoding don't want to help
Maybe you get now the point about "be more precise"
It is near to impossible to help if you tell us about something like.

The source did not contain a whole text but a bunch of strings in a kind of structure. You have to work on that structure and read the data following the structure rules.

A good starting point is to look at the producer of the data and get some information. We do not have (because you did not tell us - another precise mark) any clue about the producer.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
brechi

Registriert seit: 30. Jan 2004
823 Beiträge
 
#9

AW: $0 in stream and loading as text

  Alt 25. Aug 2014, 14:31
You have to write your own component to visualize the text.
Internal PAnsiChar/PWideChar is used and a #0 is the end of the text.

So if you use

Code:
  Memo1.Lines.Text := 'test1'#0'test2'#0;
only the "test1" will be shown.

If you dont want to save your data, then you can load the file into a TMemoryStream (or a string) and replace the #0 with another character.


Code:
var
  s: String;
  fm: TFileStream;
fm := TFileStream.Create;
fm.LoadFromFile('sadasd', fmOpenRead);
setLength(s, fm,size);
fm.Read(s[1], Length(s));
s := StringReplacte(s, #0, #1, [rfReplaceAll]);
memo1.lines.text := s;
etc.
  Mit Zitat antworten Zitat
Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.580 Beiträge
 
Delphi 11 Alexandria
 
#10

AW: $0 in stream and loading as text

  Alt 25. Aug 2014, 14:45
If you dont want to save your data, then you can load the file into a TMemoryStream (or a string) and replace the #0 with another character.
This is only unicode text, so the problem is not to replace those bytes, but to read the file with correct encoding.
If one did it this way and there is only one real unicode character inside, one would get really strange results...

Even if there is no byte order mark this code works perfectly for me:
Delphi-Quellcode:
var
  test: TStringStream;
begin
  test := TStringStream.Create('', TEncoding.Unicode);
  try
    test.LoadFromFile('c:\temp\a.txt');
    ShowMessage(test.DataString);
  finally
    test.Free;
  end;
end;
So it would be better, if you would attach a working sample code with an example file...
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


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 13:54 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