Autor Beitrag
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 20.09.04 14:21 
Hallo!

Ich stehe vor einem kniffligen Problem:

Ich habe eine Firebird-UDF erstellt und dort eine Funktion ReadBlob implementiert, sie liefert einfach den Inhalt eines Blobs als String zurück. Nun ist in manchen Feldern aber RTF-Text drin, den muss ich in Plaintext umwandeln. Hat irgendjemand eine Funktion, die soetwas ohne Umwege über Komponenten wie Richedit macht (es muss nämlich threadsicher und Kylix-kompatibel sein)?

Ich habe mir mal die RTF-Spezifikation angekuckt, es ist nicht einfach so herauszuparsen wie bei HTML.

Cu
Udontknow

PS: Nein, ich kann´s nicht im Endanwender-Programm machen, da die gegebenen Strukturen die DB-Ebene erzwingen (Excel greift per ODBC direkt die Datenbank ab). :cry:
Udontknow Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 27.09.04 10:37 
So, ich habe mir eine Routine gebastelt, die das halbwegs ordentlich erledigen kann.

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:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
function RTFToPlainText(RTF:String):String;
var i,j,h:integer;
begin
  //Sonderzeichen ersetzen
  RTF:=StringReplace(RTF,'\'+Chr(39)+'f6','ö',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'d6','Ö',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'e4','ä',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'c4','Ä',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'fc','ü',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'dc','Ü',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'df','ß',[rfReplaceAll]);

  //Fontangaben entfernen
  Repeat
    i:=Pos('{\f',RTF);
    if i>0 then
    begin
      j:=i;
      h:=1;
      Repeat
        Inc(j);
        if RTF[j]='{' then
          Inc(h);
        if RTF[j]='}' then
          Dec(h);
      Until ((RTF[j]='}') and (h=0)) or (j=Length(RTF));
      if ((RTF[j]='}') and (h=0)) then
      begin
        Delete(RTF,i,j-i+1);
      end;
    end;
  Until i=0;

  //Andere Formatbefehle entfernen
  i:=1;
  While (i<Length(RTF)) do
  begin

    if RTF[i]='\' then
    begin
      j:=i;
      While (RTF[j]<>' ')
      and (j<Length(RTF))
      and (RTF[j+1]<>'ä')
      and (RTF[j+1]<>'ö')
      and (RTF[j+1]<>'ü')
      and (RTF[j+1]<>'Ä')
      and (RTF[j+1]<>'Ö')
      and (RTF[j+1]<>'Ü')

      do
        Inc(j);
      Delete(RTF,i,j-i+1);
    end
      else Inc(i);
  end;
  RTF:=StringReplace(RTF,#$D#$A,' ',[rfReplaceAll]);
  RTF:=StringReplace(RTF,';',' ',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'{',' ',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'}',' ',[rfReplaceAll]);

  Result:=Trim(RTF);
  if Result='' then
    Result:=' ';
end;


Cu,
Udontknow