Autor Beitrag
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: So 13.06.04 09:47 
Ich weis, das gabs bestimmt schon X-mal, aber mit der suchfunktion hab ich nix gefunden.
Also, ich möchte einen String in 2 Strings teilen, und zwar am ersten Zeilenumbruch (#13#10).

Beispiel:

Ich habe:
'blablablablabla#13#10irgendwasirgendwas#13#10irgendwas'

Resultat:
1. 'blablablablabla'
2. 'irgendwasirgendwas#13#10irgendwas'

[edit] kann das vielleicht wer in sonstiges schieben ?
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 13.06.04 09:49 
ausblenden Delphi-Quelltext
1:
2:
 string1:=copy(instring,1,pos(#13#10,instring)-1);
 string2:=copy(instring,pos(#13#10,instring)+1,length(instring));


Gruß,
maxk

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
jfheins Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: So 13.06.04 10:00 
Titel: danke
Danke Funktionierte fast ...

Korrekt:
string1:=copy(instring,1,pos(#13#10,instring)-1);
string2:=copy(instring,pos(#13#10,instring)+2,length(instring));

(Der Windows-Zeilenumbruch hat 2 Bytes)
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 13.06.04 17:13 
Oops, ich verwende sonst immer nur ein Terminator :roll:

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
arnydaniel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 80

hoffentlich bald Linux
Delphi 6
BeitragVerfasst: Di 07.06.05 14:13 
Gibts da nicht irgend eine Funktion, die den String bei einem bestimmten Zeichen teit und die Teile dann in einem Array zurückgibt?
Also bei PHP gibts sowas.

_________________
Wenn jeder nur an sich denkt, wird an jeden gedacht.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Di 07.06.05 14:19 
Hier, handgebissen:
ausblenden 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:
(*****************************************************************************
 * Split  : splits string S at position of Del, return the part before *
 *      Del and modifies S to the part after Del         *
 *        S := 'LeftPart<Del>RightPart'           *
 *        V := Split (S,'<Del>')             *
 *        V = 'LeftPart'   and    S = 'RightPart'         *
 *                but                                                        *
 *        S := 'LeftPart<Del>RightPart'                 *
 *        V := Split(S,'-Del-)                   *
 *        V = 'LeftPart<Del>RightPart'    and  S = ''               *
 *****************************************************************************)

Function Split (Var S : String; 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;

Dann bekommst Du mit einer einfachen Schleife auch alle folgenden Strings raus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
  s := 'Teil1, Teil2, Noch ein Teil';
  While s<>'' Do Part.Add (Split (s,','));
...