Autor Beitrag
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: So 23.12.07 10:14 
Hallo...

Wie kann ich diesen String am besten zerlegen, das jeder einzelne Wert in einer Variable gespeichert werden kann?
:arrow: Zwischen jedem Wert ist ein Tabulator Zeichen!

ausblenden Quelltext
1:
1 12 1 3200 16 "Name" 24 0 "Topic"					

_________________
ausblenden Delphi-Quelltext
1:
if CopyAndPaste not avaible then Developer := Helpless;					
DelphiMarkus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 23.12.07 10:44 
Hallo!

Wenn man werte hat, die sich in der Länge nicht verändern kann man es so machen:(So steht es in dem Buch Delphi für Kids)
ausblenden Delphi-Quelltext
1:
Variable := Copy(String1, Length(String)-5);					

Um von dem String 5 abzuziehen und in der Variable zu speichern.
ausblenden Delphi-Quelltext
1:
Variable := Copy(String8, Length(String)-5);					

Um von dem String beim 8. Zeichen 5 abzuziehen und in der Variable zu speichern.
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: So 23.12.07 11:09 
Oder ist es Zeichengetrennt wie bei ner csv?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure StringZerlegen(lString:string;lTrennzeichen:char);
var lPos:integer;
begin
 lpos:=pos(lTrennzeichen,lString);
 while lpos>0 do
 begin
  //Variable ist copy(lString,lPos-1);
  delete(lString,1,lPos);
  lpos:=pos(lTrennzeichen,lString);
 end;
end;

zB. in StringListen speichern
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:
procedure StringZerlegen2Strings(lString:string;lTrennzeichen:char;lStrL:TStrings);
var lPos:integer;
begin
 lStrL.clear;
 lpos:=pos(lTrennzeichen,lString);
 while lpos>0 do
 begin
  //Variable ist copy(lString,lPos-1);
  lStrL.Add(trim(copy(lString,1,lPos-1)));
  delete(lString,1,lPos);
  lpos:=pos(lTrennzeichen,lString);
 end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var lStrLst:TStringList;
    i:integer;
begin
 lStrLst:=TStringList.Create;
  StringZerlegen2Strings('1'+#8+'12'+#8+'1'+#8+'3200'+#8+'16'+#8+'"Name"'+#8+'24'+#8+'0'+#8+'"Topic"',#8{Tab},lStrLst);
 //Anzeige in einer Listbox
 StringZerlegen2Strings('1'+#8+'12'+#8+'1'+#8+'3200'+#8+'16'+#8+'"Name"'+#8+'24'+#8+'0'+#8+'"Topic"',#8{Tab},listbox1.items);
end;
.#R4id Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: So 23.12.07 12:00 
Die Werte sind immer unterschidlich und es ist IMMER ein Tabulator dazwischen :!:
Die Tipps von user profile iconLorenzS könnten helfen!

[EDIT]
Die Procedure "StringZerlegen2Strings" funktioniert nur wenn man noch ein Tabulator hintendran packt, funktioniert aber perfekt!
Danke

_________________
ausblenden Delphi-Quelltext
1:
if CopyAndPaste not avaible then Developer := Helpless;					
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: So 23.12.07 12:19 
Oh sry,bin noch net ganz wach
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Procedure StringZerlegen2Strings(lString:string;lTrennzeichen:char;lStrL:TStrings); 
var lPos:integer; 
begin 
 lStrL.clear; 
 lpos:=pos(lTrennzeichen,lString); 
 while lpos>0 do 
 begin 
  //Variable ist copy(lString,lPos-1); 
  lStrL.Add(trim(copy(lString,1,lPos-1))); 
  delete(lString,1,lPos); 
  lpos:=pos(lTrennzeichen,lString); 
 end;
 if  length(lString)>0 then
  lStrL.Add(trim(lString)); 
end;
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 23.12.07 12:43 
Sollte für deine Delphi-Version so gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
with TStringList.Create do
  try
    StrictDelimiter := True;
    Delimiter := #8;
    DelimitedText := '1'#8'12'#8'1'#8'3200'#8'16'#8'"Name"'#8'24'#8'0'#8'"Topic"'// der zu zerlegende String
    if Count > 0 then
      ShowMessage(Strings[0]); // Beispiel; Zugriff auf die einzelnen Felder über Strings[I]
  finally
    Free;
  end;
.#R4id Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Mo 24.12.07 01:51 
:idea: StringReplace
Danke für eure Tipps :!:

_________________
ausblenden Delphi-Quelltext
1:
if CopyAndPaste not avaible then Developer := Helpless;