Autor Beitrag
Termi11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 11.12.08 19:47 
Hallo,

hab ein Problem mit dem copy Befehl.
Ich lese eine Text Datei aus, mit zb. Folgender Zeile:

"username password a b c { text1 text2 } { text3 text4 } { text5 text6}"

Mein Code sieht so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
str1 := copy(tmp,pos('{',tmp)+1,pos('}',tmp)-1);
tmp2 := copy(tmp,pos('}',tmp)+1,length(tmp));
str2 := copy(tmp2,pos('{',tmp)+1,pos('}',tmp)-1);
tmp2 := copy(tmp2,pos('}',tmp2)+1,length(tmp2));
str3 := copy(tmp2,pos('{',tmp2)+1,pos('}',tmp2)-1);
tmp2 := copy(tmp2,pos('}',tmp2)+1,length(tmp2));

Meiner Theorie müsste im
str1 dann "text1 text2"
str2 "text3 text4"
und im str3 "text5 text6" sein.

Erhalte jedoch:

str1: "text1 text2 } { text3 text4}"
str2: "{text5 text6}"
str3: "str5 str6}"

Mein erster Gedanke war, dass die { } Zeichen als Kommentar interpretiert werden, erhalte jedoch keine Fehlermeldung.
Es müssen auch { und } Zeichen sein.

Wo mache ich den Denkfehler?

Besten Dank!!

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am Do 11.12.2008 um 18:49
Barzi
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 11.12.08 20:20 
Ich fürchte du hast die copy-Parameter falsch verstanden:
ausblenden Delphi-Quelltext
1:
function Copy ( Source  : string; StartChar, Count  : Integer ) : string;					


Count ist nicht die Position des letzten Zeichens, welches kopiert werden soll, sondern gibt die Anzahl der zu kopierenden Zeichen vom StartChar an ...

Du müsstest es also folgendermaßen machen:
copy(str, STARTWERT, ENDWERT-STARTWERT);
STARTWERT und ENDWERT jeweils mit pos() suchen ...

Ich hoffe es klappt ;-)

Und noch ein Tipp um den Code zu vereinfachen:
Schau dir mal Suche bei Google POSEX FUNCTION an. Da kannst du zusätzlich zusätzlich einen Startwert definieren, ab dem gesucht werden soll ...


Zuletzt bearbeitet von Barzi am Do 11.12.08 20:27, insgesamt 1-mal bearbeitet
Bob Murphy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 91

XP, Ubuntu
Delphi 7 SE, Delphi 2007
BeitragVerfasst: Do 11.12.08 20:25 
Da war jemand schneller^^
Trotzdem kannste dir nochmal diese Seite angucken: www.delphi-treff.de/...]=stringverarbeitung
Termi11 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 11.12.08 22:08 
Oh Gott, das ist ja schon Peinlich :-)
Hab das komplett durcheinander geworfen!

Danke an euch Beide ! :-)