Autor Beitrag
Krefti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mi 24.01.07 09:58 
morgen zusammen..

ich möchte aus meinem memo aus 3 bestimmten zeilen einen Wert(kommazahl) auslesen.

inhalt des memos:
..
Z28:Lmax d-11-yyyy 18:46:31 156,5 dB
Z29:Lpeak d-11-yyyy 18:46:32 78,9 dB
Z30:Lmin d-11-yyyy 18:46:30 39,1 dB
..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
for i := 27 to 29 do                       //Auslesen LFmax/LFmin/Lpeak
     begin
          txt := slZeilenListe[i];         
          substring := Copy(txt,26,5);
          substring := Trim(substring);
          arrDaten[i] :=  substring;

     end;

     Leq := slZeilenListe[23];

     mDateiAnzeige.Lines.Clear;

     for i := 27 to 29 do
     begin
       MDateiAnzeige.Lines.Add(arrDAten[i]);
     end;


des funktioniert auch soweit wunderbar, aber ich denke mal, ich habe des ziemlich kompliziert gelöst oder?? meine frage ist nun, wie kann ich des wesentlich einfacher machen??
Vielen Dank schon mal für eure mühe..
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Do 25.01.07 08:54 
hmm..kann mir keiner weiter helfen oder is meine lösung gar net so schlecht wie ich denk???
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 25.01.07 09:39 
Hmm seltsam, dass das bei dir funktioniert...
Die Daten sind doch gar nicht gleich lang und das was davor steht auch nicht. Wie kann das mit funktionieren, wenn du immer 5 Buchstaben von Buchstabe 26 aus nimmst? :gruebel:

Na jedenfalls ist die Frage, was du mit einfacher meinst? Schneller? Dein Code dürfte recht schnell sein.
Kürzerer Code? Ja, das geht kürzer...
Vor allem aber universeller, nämlich für Teilstrings beliebiger Länge...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var
  i: Integer;
  tmp: TStringList;
begin
  for i := 0 to Memo1.Lines.Count - 1 do
  begin
    tmp := TStringList.Create;
    tmp.Delimiter := ' ';
    tmp.DelimitedText := Memo1.Lines[i];
    if tmp.Count > 3 then
      ShowMessage(tmp[3]);
    tmp.Free;
  end;
end;
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mo 29.01.07 10:02 
ich frag mich eigentlich auch, warum es eigentlich so funktioniert..

Vielen Dank für deinen code..
ich möchte halt die Werte auf die Art auslesen, dass ich die position des Tabstop vor den Werten herausfinde und dann von da ab die Zahlen auslese und den Rest danach abschneide..aber irgendwie bekomm ich des net so ganz hin..kann mir vielleicht doch nochmal jemand en tip oder ein Beispiel geben??

hier mal mein prinzipieller code, wie ich möchte, dass es funktioniert..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
for j := 27 to  29 do                 //Zeilennummer
     begin
           txt := slZeilenListe[j];   //die zeile in txt gespeichert
           c:=0;                      
         for i:= 1 to Length(txt) do  
         begin

              if txt[i] = #9 then    // wenn ein tabstop gfunde wird.
                 c := c + 1;         // zähler erhöhen, ansonsten gar nix machen..
                   if c = 2 then     // wenn der 2. tabstop gefunden irgendwie die schleife abbrechen und den wert danach auslesen..                                                                           
                   substring := copy(txt, { hiermöchte ich irgendwie die position des 2.tabstopps  eintragen, weiß aber net wie} ,5);                                                                                    
                   substring := trim(substring);
                   arrDaten[i] := substring;
          end;
     end;
 mDateiAnzeige.Lines.Clear;

     for i := 0 to Length(txt) do        //anzeige der Werte in memo ????
     begin
       MDateiAnzeige.Lines.Add(arrDAten[i]);
     end;


Vielen Dank für eure hilfe..bin grad ziemlich am verzweifle..
ssb-blume
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 375
Erhaltene Danke: 7

XP, W7, W8
Deutschland
BeitragVerfasst: Mo 29.01.07 13:02 
So:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
   if c=2 then
   begin
     substring := copy(txt, i+1, 5);
     substring := trim(substring);
     arrDaten[xxx] := substring;
     break;
  end;


i ist die Position des Trennzeichens, i+1 also das naechste Zeichen.
Achtung!! xxx muss eine andere Variable sein und yseparat weiter gezaehlt werden!

_________________
Brain: an apparatus with which we think we think.
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mo 29.01.07 13:42 
erstmal Vielen dank für deine antwort..

er fügt mir jetzt anstatt den Werten einfach 4 Leerzeilen ein..was machn ich noch falsch?

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:
for j := 27 to  29 do
     begin
           txt := slZeilenListe[j];
           c:=0;
         for i:= 1 to Length(txt) do
         begin

              if txt[i] = #9 then
                 c := c + 1;
                   if c = 2 then
                      substring := copy(txt, i+1, 5);
                      substring := trim(substring);
                      arrDaten[j] := substring;
                      break;
          end;
     end;

     mDateiAnzeige.Lines.Clear;

     for j := 27 to 29 do
     begin
       MDateiAnzeige.Lines.Add(arrDAten[j]);
     end;
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Mo 29.01.07 13:51 
user profile iconKrefti hat folgendes geschrieben:
erstmal Vielen dank für deine antwort..

er fügt mir jetzt anstatt den Werten einfach 4 Leerzeilen ein..was machn ich noch falsch?

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:
for j := 27 to  29 do
     begin
           txt := slZeilenListe[j];
           c:=0;
         for i:= 1 to Length(txt) do
         begin

              if txt[i] = #9 then
                 c := c + 1;
                   if c = 2 then
                      substring := copy(txt, i+1, 5);
                      substring := trim(substring);
                      arrDaten[j] := substring;
                      break;
          end;
     end;

     mDateiAnzeige.Lines.Clear;

     for j := 27 to 29 do
     begin
       MDateiAnzeige.Lines.Add(arrDAten[j]);
     end;


Hi Krefti.

Du musst nach: if c = 2 noch ein begin einfügen, wies dein vorposter schon gesagt hat ;)

Gruss, rob
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Mo 29.01.07 14:14 
vielen dank..hab ich irgendwie übersehen..vielen dank an euch;)