Autor Beitrag
manfred07
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 56



BeitragVerfasst: Mi 13.04.05 16:41 
Hi DF-Gemeinde,

ich hoffe mir kann einer weiter helfen.
Ich möchte aus einer Listbox aus der ersten Zeile das Zeichen ^ (Circumflex) suchen
und den danachfolgenden Text einer TLabel.Caption zuweisen.

Habe schon in der Delphihilfe gesucht und gefunden aber, ich weiß nicht wie ich es
anwenden muß.

^ Ein Circumflex am Anfang einer Zeichenkette findet den Anfang einer Zeile

Wie ich die ganze Zeile anzeigen kann das bekomme ich ja hin, aber das mit
dem Circumflex :cry:

Label1.Caption:=Listbox1.Items[0]; // Da zeigt er mir die gesammte Zeile an.

Danke im voraus

Manfred
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mi 13.04.05 16:52 
Also ich mach mal n Vorschlag (den schreib ich jetzt so zusammen-->iss nicht getestet und kann Fehler enthalten, aber der Ansatz müsste zu 99% stimmen):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
Procedure SchowText;
var s: string;
begin
s := form1.ListBox1.Items.Strings[0];
s := copy(s, pos(s, '^'), (length(s) - (pos(s, '^') + 1));
Form1.Label1.Caption := s;
end;


Ich hoffe es stimmt. Bei der Pos- Funktion bin ich mir jetzt net sicher, ob zuerst s und dann '^' kommt oder andersherum, aber das siehst du ja dann.

Ciao!

_________________
Programmers never die, they just GOSUB without RETURN
HECHT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24


D7
BeitragVerfasst: Mi 13.04.05 17:00 
Du könntest das Zeichen abschneiden? oder duch Leerstring ersetzten?
Probiers mal damit,

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var Par: TReplaceFlags;
begin
  Par:=[];
  Par:=[rfReplaceAll,rfIgnoreCase];
  // ohne rfReplaceAll wird nur die erste Fundstelle ersetzt
  // durch rfIgnoreCase wird Groß- und Kleinschreibung ignoriert
  caption:=StringReplace('1234512345', '1', '9', Par);
  // '1' ist der zu ersetzende Teil, '9' der neu eingefügte Teil
end;


macht aus 1234512345 --> 9234592345
manfred07 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 56



BeitragVerfasst: Mi 13.04.05 17:50 
Hi alias5000,

Danke schön genau das hatte ich gesucht :lol:
mußte s und ^ tauschen und statt +1 -1 ersetzen.
Aber das Circumflex wird auch mit angezeigt :?:
Sollte es nicht den Anfang einer Zeichenkette finden?

Wie bekomme ich das den jetzt weg?


@ Hi Hecht,

auch dir ein Danke schön für deine schnelle Antwort.


Gruß Manfred
manfred07 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 56



BeitragVerfasst: Mi 13.04.05 18:36 
Hi alias5000,

habe es selber hin bekommen :lol: .....
Code hier:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
s := ListBox1.Items.Strings[0];
s := copy(s, pos('^',s), (length(s) - (pos('^',s) -1)));
s := StringReplace(s, '^', '', [rfReplaceAll]); // löscht das ^ Zeichen wieder
Label1.Caption := s;



Gruß Manfred

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
SvenAbeln
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 334
Erhaltene Danke: 3



BeitragVerfasst: Mi 13.04.05 18:53 
Hallo

Zitat:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
s := ListBox1.Items.Strings[0];
s := copy(s, pos('^',s), (length(s) - (pos('^',s) -1)));
s := StringReplace(s, '^', '', [rfReplaceAll]); // löscht das ^ Zeichen wieder
Label1.Caption := s;



Warum kopierst du nicht einfach nur den Teil nach dem ^

ausblenden Delphi-Quelltext
1:
s := copy(s, pos('^',s)+1,.....