Autor Beitrag
Terra23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: Sa 21.07.07 22:51 
Hi!

Ich habe folgende Prozedur im Programm:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
S:=Edit1.Text;
For A:=0 To TreeView1.Items.Count-1 Do
  If TreeView1.Items[A].Text=S
  Then ListBox1.Items.Add(TreeView.Items[A]);


Mit dieser Prozedur kann ich prüfen, ob das Item innerhalb eines Treeviews exakt mit dem Suchstring S übereinstimmt.

Nun möchte ich allerdings herausfinden, ob der Suchstring S auch irgendwo in dem Item des TreeViews steht, also z.B.

Suchstring S = Forum

TreeView Item = Delphi-Forum.de

Nun soll er mir dieses Item auch in die ListBox machen, da der Suchbegriff S ja in dem Item vorkommt.

Ich hoffe, ihr versteht mein Problem einigermaßen.

MfG

Terra

_________________
Hasta La Victoria Siempre
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: Sa 21.07.07 23:11 
Schau dir mal die Pos-Funktion an, evtl. zusätzlich noch die (Ansi-)Upper/Lowercase-Funktion.
Terra23 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: Do 09.08.07 17:25 
Hi!

Das habe ich getan. Ich habe auch schon einige Versuche mit Copy und so versucht aber ich komme nicht weiter. Dazu reichen meine Kenntnisse in Delphi einfach nicht aus. ;)

Kann mir jemand vielleicht beim Code helfen?

Meine Idee war folgende:

1) Ich gehe mit einer Schleife die Items durch.
2) Ich nehme das jeweilige Item, beginne an erster Stelle.
3) Ich kopiere den Text von der ersten Stelle an in der Länge wie mein Suchstring lang ist.
4) Stimmt der String, gehe ich zum nächsten Item. Stimmt er nicht, beginne ich mit Schritt 2 aber diesmal an zweiter Stelle.


Ich stehe echt auf dem Schlauch..

_________________
Hasta La Victoria Siempre
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Do 09.08.07 18:33 
Ich hätte da ein Workaround anzubieten:

Mit StringReplace änderst du den aktuellen string der TreeView um irgendeinen Zusatzstring, wenn der string aus s vorkommt und vergleichst anschließend, ob dein urpsrünglicher String der selbe wie der neue ist.

Hier veranschaulicht mit Hilfe einer Listbox:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  for i := 0 to Listbox.Items.Count - 1 do
    begin
      before := Listbox.Items.Strings[i];
      after := StringReplace(before, s, '_', [rfIgnoreCase]); // <-- nicht case-sensitve
        if before <> after then
          ShowMessage('In Zeile ' + inttostr(i+1) + ' kommt ' + s + ' vor.');
    end;


Ungetestet...

[edit]Kommst du wirklich aus Busenberg?[/edit]

Gruß

Calculon
--
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 09.08.07 18:48 
Stringreplace? Sorry, aber :autsch:. Der richtige Hinweis mit der pos-Funktion kam doch schon...:roll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
 if pos(einKurzerString, einLangerString) > 0 then
  Showmessage(einkurzerString + ' ist in ' + einLangerString + ' enthalten.')
else
  Showmessage(einkurzerString + ' ist nicht in ' + einLangerString + ' enthalten.');


Wenn ich wissen will, ob in meinem Bierglas noch Bier drin ist, mach ich ja auch kein Foto davon, dreh es um, mach wieder ein Foto und gucke, ob die Bilder gleich aussehen und/oder der Boden nass ist, sondern guck einfach nach, ob noch Bier drin ist...

_________________
We are, we were and will not be.
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Do 09.08.07 18:53 
Ja schon, aber der Aufwand wird größer, wenn er das ganze nicht Case-Sensitive haben will.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 09.08.07 18:58 
user profile iconCalculon hat folgendes geschrieben:
Ja schon, aber der Aufwand wird größer, wenn er das ganze nicht Case-Sensitive haben will.

Dann pack ich ein AnsiUpperCase um beide Strings rum (der Tip kam auch schon).

Wenn ich wissen will, ob Bier oder Kölsch in meinem Glas ist, drehe ich es auch nicht um...

_________________
We are, we were and will not be.
Terra23 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: Do 09.08.07 19:25 
@Gausi: Danke, das funktioniert so. Nun frage ich mich aber: Warum hab ich Idiot das nicht hinbekommen?

Und: Nun will ich ein Bier.

Danke für die Hilfe.

Terra

PS: Du stehst nun auf etcg.de in meiner Sig mit dem Spruch. ;)

_________________
Hasta La Victoria Siempre