Autor Beitrag
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 06.11.05 19:21 
Also ich habe einen String der so aussieht: 'Wort1 - Wort2'

nun will ich Wort1 und Wort2 extrahieren.

greetz


EDIT: Falsch formuliert. Es kann auch so sein: Wort1 - Wort2 Wort3, also ich will dann Wort1 einzelnd haben und Wort2 und 3 miteinander (mit leerzeichen).

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 06.11.05 19:25 
Geht zum Beispiel so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
NeuerString1 := Copy(AlterString, 1, Pos('-', AlterString) - 2);
NeuerString2 := Copy(AlterString, Pos('-', AlterString) + 2, Length(AlterString) - Pos('-', AlterString) + 2);

// geht auch so -->
NeuerString1 := Copy(AlterString, 1, Pos('-', AlterString) - 2);
Delete(AlterString, 1, Pos('-', AlterString) + 2);
NeuerString2 := AlterString;

oder mit einer Funktion, deren Name ich gerade nicht weiß.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Born-to-Frag Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 06.11.05 19:54 
Ich habe es jetzt so gelöst:

ausblenden Delphi-Quelltext
1:
2:
3:
wort2 := 'wort1 - wort2';
  wort1 := copy(wort2, 0, pos(' ',wort2) - 1);
  delete(wort2, 1, pos(' ', wort2) + 1);


Habe ich von wo anders.
Da ich aber auch wissen will was ich da mache, könnte mir einer erklären was das mit den zahlen -1 +1 etc. auf sich hat? das pos weiß ich.

greetz

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 06.11.05 19:56 
Ist genau das gleiche wie bei mir.
Das +1 bedeutet einfach das Zeichen nach dem ' '.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 06.11.05 20:28 
Das hier verwende ich seit ca. 25 Jahren. Der Vorteil ist, das die Funktion auch dann funktioniert, wenn das Trennzeichen (bzw. der Trennstring) gar nicht vorhanden ist.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Function Split (Var S : String; Const Del : String) : String;
Var
  p : Integer;

Begin
  p := Pos(Del,S);
  if p=0 then Begin
    Result := s;
    s := '';
    end
  else begin
    Result := Copy(s,1,p-1);
    s := Copy(s, p + length(Del), length (s));
    End;
End;

Allgemein funktioniert sie so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  s := '<Word><Del><Rest>';
  w := Split (s, '<Del>');
  // w = '<Word>' und s = '<Rest'>
  w := Split (s, '<Del>');
  // w = '<Rest>' und s = ''

_________________
Na denn, dann. Bis dann, denn.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 06.11.05 20:46 
Ich hab alzaimar's Methode mal noch etwas angepasst:

ausblenden OIncProcs.pas
 
2890:
2891:
2892:
2893:
2894:
2895:
2896:
2897:
2898:
2899:
2900:
2901:
2902:
2903:
2904:
{ ... }
//DF by alzaimar:
//http://www.delphi-forum.de/viewtopic.php?p=308367#308367
//Minor changes since original

Function Split(Var S: String; Const Del: String): String;
Var
    P: Integer;
Begin
    P := Pos(Del, S);
    If P = 0 Then
        P := Length(S) + 1;

    Result := Copy(S, 1, P - 1);
    Delete(S, 1, P + Length(Del));
End;


Funktioniert nach genau dem gleichen Prinzip, brauch aber weniger Source.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 06.11.05 21:33 
für SO sachen fänd ich das programm Suche in: Delphi-Forum, Delphi-Library FUCS unglaublich praktisch :)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 06.11.05 21:42 
user profile iconBenBE hat folgendes geschrieben:
Ich hab alzaimar's Methode mal noch etwas angepasst...

Dein Einverständnis vorausgesetzt, habe ich die von Dir optimierte Funktion in meine Sammlung "Alsadeimlaudejagegrau"* (mit Quellenangabe :wink:) übernommen.
*Alzaimars Sammlung der im Laufe der Jahre gesammelten Grausamkeiten"

_________________
Na denn, dann. Bis dann, denn.
Born-to-Frag Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 06.11.05 22:10 
Danke für die vielen und SEHR hilfreichen antworten!!

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.