Autor Beitrag
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Fr 14.10.05 20:01 
ich weiß nich ob ich grad nen riesiegen denkfehler hab aber ich bekomms grad wirklich gar nich gebacken:
ich möchte aus einem string jedes wort in ein stringliste eintragen, hab irgendwie schon den easy helper, die forensuche und die delphiosuchen hoch und runter durchgesehn nach etwas was mir weiterhelfen könnte, aber scheiter dann irgendwie schon beim 2. wort, hab mir da speziell, pos(); delete() und copy() angesehn aber kein plan wie ichs damit anstelln soll
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 14.10.05 20:05 
Versuchs mit ner TStringList:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
aTStringList.Delimiter:=' ';
aTStringList.CommaText:=DeinString;
Wort1:=aTStringList[0];
Wort2:=aTStringList[1];
Wort3:=aTStringList[2];

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Fr 14.10.05 20:19 
user profile iconJayEff hat folgendes geschrieben:
Versuchs mit ner TStringList:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
aTStringList.Delimiter:=' ';
aTStringList.CommaText:=DeinString;
Wort1:=aTStringList[0];
Wort2:=aTStringList[1];
Wort3:=aTStringList[2];


das ist nicht ganz richtig
es muss so sein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
aTStringList.Delimiter:=' ';
aTStringList.DelimitedText:=DeinString;
Wort1:=aTStringList[0];
Wort2:=aTStringList[1];
Wort3:=aTStringList[2];


CommaText würde das nach Kommata trennen
Ironwulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Fr 14.10.05 20:38 
danke für die antworten nur kommt in der ersten zeile schon ein fehler "Delimiter ist undefinierter bezeichner), hab atstringlist als variable definiert und in der form. create mit atstringlist:= tstringlist.create initialisiert
falls die version da eine rolle spielt, ich verwende delph 3 pro
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 14.10.05 20:47 
Hallo,

zur Info, eine StringListe in D3 kennt '.Delimiter' noch nicht.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
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: Fr 14.10.05 20:49 
Vielleicht kennt die Stringlist aber schon CommaText.
Dann einfach die Leerzeichen durch Kommas ersetzen.

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



BeitragVerfasst: Fr 14.10.05 20:56 
das hat ich mir auch schon überlegt, nur dann kommt in der 2. zeile (aTStringList.CommaText:=Edit1.Text;)
der fehler: zugriffsverletzung bei adress xxx in projekt yyy. lesen von adresse zzz

mein code sieht so aus, vllt mach ich da irgendwsas 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:
var
  Form1: TForm1;
  ATStringlist:TStringlist;
  wort1, wort2, wort3: String;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
aTStringList.CommaText:=' ';
aTStringList.CommaText:=Edit1.Text;
Wort1:=aTStringList[0];
Wort2:=aTStringList[1];
Wort3:=aTStringList[2];
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ATStringlist:= TStringlist.Create;
end;


Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt
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: Fr 14.10.05 21:01 
ausblenden Delphi-Quelltext
1:
aTStringList.CommaText := ' ';					

Die Zeile darfst du nicht nehmen.
Du musst hier dann mit StringReplace(); arbeiten.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  SList: TStringList;
begin
  SList := TStringList.Create;
  SList.CommaText := StringReplace(Edit1.Text, ' ', ',', [rfReplaceAll]);
  ShowMessage(SList[0] + '-' + SList[1] + '-' + SList[2]);
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)


Zuletzt bearbeitet von GTA-Place am Fr 14.10.05 21:04, insgesamt 1-mal bearbeitet
Kokel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 79

XP Prof
delphi 2006 Prof.
BeitragVerfasst: Fr 14.10.05 21:01 
SO:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
 Var
 dummi,dummi2,orginaltext:string;
 begin
 dummi2:=orginaltext;
 dummi:=copy(dummi2,0,pos(' ',dummi2)-2);
 delete(dummi2,1,pos(' ',dummi2)+1);


machen , watchen und analysieren.
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Fr 14.10.05 21:07 
Zitat:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
aTStringList.CommaText:=' ';
aTStringList.CommaText:=Edit1.Text;
Wort1:=aTStringList[0];
Wort2:=aTStringList[1];
Wort3:=aTStringList[2];
end;


und

Zitat:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Var
 dummi,dummi2,orginaltext:string;
 begin
 dummi2:=orginaltext;
 dummi:=copy(dummi2,0,pos(' ',dummi2)-2);
 delete(dummi2,1,pos(' ',dummi2)+1);



--> Warum so schwierig... :gruebel:
Also, wenn du die Wörter aus dem Edit nur in eine StringList eintragen willst
geht das ganz einfach:

ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Sl1: TStringList;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Sl1 := TStringList.Create;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Sl1.CommaText := Edit1.Text;
  Memo1.Lines := SL1;
end;

end.


Danniolo
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: Fr 14.10.05 21:09 
Da aber CommaText Wörter nach dem Komma trent, ist meine Möglichkeit oben besser.

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



BeitragVerfasst: Fr 14.10.05 21:11 
Zitat:
Da aber CommaText Wörter nach dem Komma trent, ist meine Möglichkeit oben besser.

Stimmt nicht!
CommaText trennt auch nach Leerzeichen! :wink:
(Ausprobiert mit Delphi 3 Prof und Delphi 2k5 PE) :wink:
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: Fr 14.10.05 21:16 
Dann ist ja gut und alles einfach :-)

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



BeitragVerfasst: Fr 14.10.05 21:27 
joa danke funktioniert, lustisch was 3 zeilen alles können ;D
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Fr 14.10.05 21:30 
Zitat:
Dann ist ja gut und alles einfach :-)

Eben :wink:
Zitat:
joa danke funktioniert, lustisch was 3 zeilen alles können ;D

ja, irgendwie schon lustig. Ich saß auch mal vor diesem Problem
und hab... naja min 2h drangesessen, hab rumprobiert (mein Internet hat grad nicht gefunzt)
und hab mich am Schluss richtig geärgert, dass das nur son bissl Kram war... :wink:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 14.10.05 21:56 
Hallo,

user profile iconDanniolo hat folgendes geschrieben:
...CommaText trennt auch nach Leerzeichen! :wink:

eben, nach Leerzeichen und nach Komma :wink:
Außerdem was ist mit den Satzzeichen?
ausblenden Quelltext
1:
'Dies ist ein Satz. Jetzt noch ein Satz; etwas länger.'					

Ausgabe:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Dies
ein
etwas
ist
Jetzt
länger.
noch
Satz.
Satz;



Da hilft auch sl.Delimeter := ' ' bei neueren Delphi-Versionen nicht weiter,
oder kann man da mehrere Delimeter angeben?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Fr 14.10.05 23:33 
Wenn du die Satzzeichen nicht brauchst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  SL: TStringList;
  s: string;

[...]

s:=Edit1.Text;
s:=StringReplace(s, '.', ' ', [rfReplaceAll]);
s:=StringReplace(s, ',', ' ', [rfReplaceAll]);
s:=StringReplace(s, ';', ' ', [rfReplaceAll]);
s:=StringReplace(s, ':', ' ', [rfReplaceAll]);
s:=StringReplace(s, '!', ' ', [rfReplaceAll]);
s:=StringReplace(s, '?', ' ', [rfReplaceAll]);
[...]
SL.CommaText:=s;


Wenn du die Satzzeichen ebenfalls als "Wörter" in der Liste haben willst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  SL: TStringList;
  s: string;

[...]

s:=Edit1.Text;
s:=StringReplace(s, '.', ' . ', [rfReplaceAll]);
s:=StringReplace(s, ',', ' , ', [rfReplaceAll]); // das klappt wahrscheinlich nicht, da das Komma ja ebenfalls als Trennzeichen dient!
s:=StringReplace(s, ';', ' ; ', [rfReplaceAll]);
s:=StringReplace(s, ':', ' : ', [rfReplaceAll]);
s:=StringReplace(s, '!', ' ! ', [rfReplaceAll]);
s:=StringReplace(s, '?', ' ? ', [rfReplaceAll]);
[...]
SL.CommaText:=s;

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 14.10.05 23:41 
Hallo,

@user profile iconGrishnak: das wird ihm nicht weiter helfen, Delphi 3 kennt kein StringReplace:wink:
user profile iconIronwulf hat folgendes geschrieben:
danke für die antworten nur kommt in der ersten zeile schon ein fehler "Delimiter ist undefinierter bezeichner), hab atstringlist als variable definiert und in der form. create mit atstringlist:= tstringlist.create initialisiert
falls die version da eine rolle spielt, ich verwende delph 3 pro

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 15.10.05 00:14 
Hallo,

etwas zum erweitern, verbessern, verschnellern :wink: :
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:
27:
28:
29:
30:
var z : Integer;
    v : set of Char;
    s,sErg : String;
    sl : TStringList;
begin
  sl := TStringList.Create;
  sl.Sorted := True;
  sl.Duplicates := dupIgnore;
  try
    v := [' ','.',',',';',':','!','?',#13,#10];//kann erweitert werden
    s := 'ich weiß nich ob ich grad nen riesiegen denkfehler hab aber ich bekomms grad wirklich gar nich gebacken:'+#13#10
        +'ich möchte aus einem string jedes wort in ein stringliste eintragen,'+#13#10
        +'hab irgendwie schon den easy helper, die forensuche und die delphiosuchen hoch'+#13#10
        +'und runter durchgesehn nach etwas was mir weiterhelfen könnte,'+#13#10
        +'aber scheiter dann irgendwie schon beim 2. wort,'+#13#10
        +'hab mir da speziell, pos(); delete() und copy() angesehn aber kein plan wie ichs damit anstelln soll';
    for z := 0 to Length(s) do
      if not (s[z] in v) then
        sErg := sErg+s[z]
        else
          if sErg <> '' then
            begin
            sl.Add(sErg);
            sErg := '';
            end;
  finally
    Memo1.Text := sl.Text;
    sl.Free;
  end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Sa 15.10.05 00:39 
@Lannes: War mir nicht bekannt!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!