Autor Beitrag
Dr. Gombi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 25



BeitragVerfasst: Mo 05.08.02 17:37 
Hallo Leute!

Ich hab ein Problem: (Bin Anfänger - also bitte nicht auslachen! Hab in ner anderen Newsgroup ziemlich schlechte Erfahrungen gemacht...)

Ich habe einen String im Format:
"2002-04-21: blablablubber"

Den möchte ich jetzt "aufsplitten", sodass ich einzelne Strings mit dem Inhalt "2002","04","21" und "blablablubber" bekomme.
Wie geht das :?:

Danke für eure Hilfe!

Andi
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 05.08.02 18:33 
Hi,

mit der Funktion Copy kannst Du bestimmte Bereiche von einem String bekommen. Schau mal in der Hilfe nach... dort wird die Funktion Beschrieben!

Gruß
DBR
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Mo 05.08.02 18:35 
Die Frage ist, ob deine Strings alle so aufgebaut sind, wie der beschriebene. Wenn ja, dann ist es ganz einfach:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button4Click(Sender: TObject);
var
s,s1,s2,s3,s4:string;
begin
s:='2002-04-01: Test-Text-123';
s1:=copy(s,1,4);
s2:=copy(s,6,2);
s3:=copy(s,8,2);
s4:=copy(s,13,length(s)-12);
end;

gruss DBR
t-ob-i
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 31



BeitragVerfasst: Mo 05.08.02 21:27 
Hallo,

also ich würde dir jetzt eine Unit für Reguläre Ausdrücke vorschlagen.

Dazu z.B. Was sind reguläre Ausdrücke
und anso.virtualave.net/...i_stuff.htm#TRegExpr (mit deutscher Hilfe)

Edit: Wobei das auch erst bei komplexeren Abfragen zu gebrauchen ist :D

Tobias
Dr. Gombi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 25



BeitragVerfasst: Di 06.08.02 19:14 
DBR hat folgendes geschrieben:
Die Frage ist, ob deine Strings alle so aufgebaut sind, wie der beschriebene.

Ja, sind sie! Zumindest der Datumsteil!
DBR hat folgendes geschrieben:
Wenn ja, dann ist es ganz einfach:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button4Click(Sender: TObject);
var
s,s1,s2,s3,s4:string;
begin
s:='2002-04-01: Test-Text-123';
s1:=copy(s,1,4);
s2:=copy(s,6,2);
s3:=copy(s,8,2);
s4:=copy(s,13,length(s)-12);
end;

gruss DBR

Danke, genau das, was ich gebraucht habe!

Andi