Autor Beitrag
freshness
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43

Win XP Pof, Vista
Delphi 2006
BeitragVerfasst: Di 27.03.07 11:12 
Hi,

habe folgendes Problem, ich lese ganz normal, also mit AssignFile und readLN, eine Textdatei ein. Die Textdatei liegt lt. Beschreibugn im ASCII Format vor.
Umlaute und Sonderzeichen werden aber nicht richtig dargestellt.
Wenn ich die Datei mit dem EditPad (übrigens ein cooles tool - www.editpad.de/editpadlite.html)
öffne werden diese standardmäßig im Format Windows 1252 geöffnet und Umlaute etc. werden durch falsche Zeichen dargestellt.
Wenn ich in das DOS 850 Format encode passt es.
Wie kann in Delphi eingestellt werden, dass die datei im richtigen Format gelesen wird.
Oder wie kann ich die Datei in das DOS 850 Format konvertieren / encoden ?

Thx

freshness
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Di 27.03.07 15:34 
Hi,

also dein beschriebenes Problem hatte ich auch mal; allerdings nur bei Konsolenanwendungen. Habe dann zwei functions geschrieben, die ö, ä, ü, Ö, Ä, Ü, ß vom ANSI-Format ins DOS-Format (text_in) und umgekehrt (text_out) konvertieren:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
function replace(value: string; find_string, replace_by: string): string;
var
i: integer;
begin
   repeat
       i :=  pos(find_string, value);
       if i>0 then
         begin
           delete(value, i, length(find_string));
           if replace_by <> '' then insert(replace_by, value, i);
         end;
    until
    pos(find_string, value) = 0;
    result := value;
end;

function  text_in(str: string): string;
begin
  str := replace(str, #148, #246);
  str := replace(str, #153, #214);
  str := replace(str, #132, #228);
  str := replace(str, #142, #196);
  str := replace(str, #129, #252);
  str := replace(str, #154, #220);
  str := replace(str, #225, #223);
  result := str;
end;

function  text_out(str: string): string;
begin
  str := replace(str, #246, #148);
  str := replace(str, #214, #153);
  str := replace(str, #228, #132);
  str := replace(str, #196, #142);
  str := replace(str, #252, #129);
  str := replace(str, #220, #154);
  str := replace(str, #223, #225);
  result := str;
end;


wobei die function text_out für dich interessant sein dürfte.

Benutzung:

ausblenden Delphi-Quelltext
1:
writeln(text_out(str)); // <-- str [var string], welches die ANSI-Codes für ö,ä,ü,Ö,Ä,Ü,ß besitzt					


Gruß

Calculon
--
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 27.03.07 15:55 
Sag mal, ist die Funktion "replace" bei dir nicht ziemlich genau das selbe wie StringReplace mit [rfReplaceAll] gesetzt? :gruebel:

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Di 27.03.07 16:01 
JayEff hat folgendes geschrieben:
Sag mal, ist die Funktion "replace" bei dir nicht ziemlich genau das selbe wie StringReplace mit [rfReplaceAll] gesetzt?

Ja und ohne rfIgnoreCase, aber damals kannte ich StringReplace noch nicht ;-) und die Funktion steht halt noch so in meiner Unit.

Gruß

Calculon
--
freshness Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43

Win XP Pof, Vista
Delphi 2006
BeitragVerfasst: Do 29.03.07 09:38 
Titel: OemToChar
Hi,

in diesem Fall löste der Befehl
OemToChar(PChar(),PChar());
mein Problem und ich hab wieder ÜüÄäÖö und Konsorten.

THX
freshness