Autor Beitrag
Ace87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Mo 30.10.06 15:38 
Hallo
Ich wollte mal Fragen, ich ich einen Text auseinander rupfe.
Im meinem beipiel habe ich einen String, der mit ' Öffne Word' gefüllt ist;
und ich will nur Word rausfiltern, weil ich Word dann öffnen will.
kann mir jemand helfen?? ich habe keine Ahnung, wo ich zu suchen anfangen soll.

Mit freundlichen Grüßen

Ace
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 30.10.06 15:43 
Schaue dir mal Pos und Copy an, damit kommst du weiter. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.10.06 15:44 
Naja, generell mit Pos (Position eines Strings in einem anderen suchen), Copy (Teil eines Strings kopieren) und Delete (Teil eines Strings loeschen). Dazu dann PosEx, wenn man eine weitere Position eines Strings hinter dem ersten Vorkommen suchen willst.
Freiberger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

WIN XP
Delphi 7
BeitragVerfasst: Mo 30.10.06 15:45 
Hy,
versuche es doch mal mit stringreplace.
Ersetze das Wort 'Öffne' einfach durch ''
dann löschst du mit Trim noch die überflüssigen Leerzeichen...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.10.06 15:47 
Naja, aber ich nehme an, dass er auch erstmal rausfinden muss, ob da Oeffne steht...
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Mo 30.10.06 15:49 
Ne die Abfrage, ob vorne öffnen steht habe ich schon
braucht nur den Text hinter Öffnen
Freiberger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

WIN XP
Delphi 7
BeitragVerfasst: Mo 30.10.06 15:52 
oder du machst es mit TStringlist.
schau mal unter CommaText und DelimitedText.

Da kannst du auch lange text in einzelne Wörter zerlegen...
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mo 30.10.06 15:53 
oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
 s: string;
 p: integer;
begin
 s := 'Oeffne Word';
 p := pos('Word',s);
 label1.Caption := copy(S,p,(1+length(S)- p));

copy ab gesamtlänge des strings - länge deines wortes = word ;)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 30.10.06 15:55 
Na denn kannst du ja mit Pos, Copy, Delete und Length alles erledigen. Alternativ ginge der Einsatz von StringReplace. Je nachdem, wie Du vorgehen möchtest. Eine Übersicht mit Beispielen zu String-Operationen findest du auch auf meiner Web-Site in den "Tutorials".


Zuletzt bearbeitet von jasocul am Mo 30.10.06 15:56, insgesamt 1-mal bearbeitet
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Mo 30.10.06 15:55 
ok habe es so gelöst

ausblenden Delphi-Quelltext
1:
StringReplace(Text,'Öffne','',[rfIgnoreCase])					


hoffe das geht so
weil ich das gerade nicht ausprobieren kann
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.10.06 15:55 
Naja, dann mach doch einfach
ausblenden Delphi-Quelltext
1:
Delete(DeinString, 1, Length(ZuEntfernenderString));					

Beispiel:
ausblenden Delphi-Quelltext
1:
Delete(' Oeffne Word'1, Length(' Oeffne '));					

Natuerlich werden das dann Variablen sein, das Beispiel dient nur der Illustration...
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Mo 30.10.06 15:58 
also vielleicht noch zur erläuterung
ich weiß nicht was hinter Öffne steht

Word war jetzt nur ein beispiel
will das so machen, dass da irgend was hinter stehen kann
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mo 30.10.06 16:12 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
 s: string;
 p: integer;
begin
 s := 'Oeffne DiesUndDasJenesUndAlles';
 p := length(S)-6// Oeffne hat 6 Buchstaben
 label1.Caption := Trim(copy(S,7,p)); //an 7, da 6zeichen+ein leerzeichen
so gehts ;)
sofer nur "Oeffne XY" der Text ist! ;)


Zuletzt bearbeitet von Marc. am Mo 30.10.06 16:19, insgesamt 2-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.10.06 16:13 
user profile iconAce87 hat folgendes geschrieben:
also vielleicht noch zur erläuterung
ich weiß nicht was hinter Öffne steht

Word war jetzt nur ein beispiel
will das so machen, dass da irgend was hinter stehen kann

Genau macht ja der Code mit Delete, den ich direkt vor diesem Zitat von dir gepostet habe...

Der loescht eben das ' Oeffne ' davor und in dem String ist danach nur noch alles, was dahinter steht drin.
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Mo 30.10.06 16:21 
würde aber nicht funktionieren, wenn man ' Oeffne Word' oder noch mehr leerzeichen davor schreibt
schreiben würde oder??
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mo 30.10.06 16:24 
Dann entfernst du halt die leerzeichen, die vor und hinter den wörtern stehen, mit Trim!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
 s: string;
 p: integer;
begin
 s := ' Oeffne DiesUndDasJenesUndAlles';
 p := length(Trim(S))-6// Oeffne hat 6 Buchstaben
 label1.Caption := Trim(copy(Trim(S),7,p));
;)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.10.06 16:31 
Was meinst du, koennte nicht funktionieren? Der Befehl Delete loescht einfach die angegebene Anzahl von Zeichen. Und wegen dem Umlaut: Ich sitze hier an einem Solaris Betriebssystem, da hab ich keine Umlaute. Deshalb das Oe und so...
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Mo 30.10.06 16:31 
ok vielen dank
Probiere das gleich mal aus
aber kleine Frage zu dem von mir

ausblenden Delphi-Quelltext
1:
StringReplace(Text,'Öffne','',[rfIgnoreCase])					


würde das auch funktionieren???
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.10.06 16:33 
Klar, aber der Befehl ist in diesem Fall gar nicht notwendig. Der braucht naemlich vermutlich laenger, weil er eigentlich fuer das Ersetzen mehrerer Vorkommnisse eines Strings gedacht ist und ausserdem weitere Optionen hast (case-sensitive und so).
Freiberger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

WIN XP
Delphi 7
BeitragVerfasst: Mo 30.10.06 16:33 
bei mir geht es wunderbar...
Text:= Trim( StringReplace(Text,'Öffne','',[rfIgnoreCase]) );