Autor Beitrag
bruce185
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Mo 09.07.07 12:53 
Hallo,
ich möchte gerne das was vor dem = zeichen ist, in einer Variable speichern, ich hab das nur nach dem = zeichen hinbekommen:

ausblenden Delphi-Quelltext
1:
2:
3:
s2 := ListBox1.Items[0]; Delete(s2, 1, pos('=', s2));
Delete(s2, 1, pos(' ', s2));
ListBox2.Items.Add(s2);


z.B. Test = Test1
nur wie kann ich jetzt das was vor dem = zeichen ist, in einer Variable speichern?

Vielen Dank schonmal.

MfG
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Mo 09.07.07 12:58 
Ein ähnliches Problem hatte ein anderer User vor nicht all zu langer Zeit hier. Vielleicht hilft Dir das schon weiter.

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 09.07.07 13:48 
Moin!

user profile iconbruce185 hat folgendes geschrieben:
z.B. Test = Test1
ausblenden Delphi-Quelltext
1:
s2 := ListBox1.Items[0];					

Die .Itemsvon einer Listbox sind doch TStrings, damit sollte man doch dann per .Names[]und per .Values[]drauf zugreifen können. :idea: Wozu selbst zerlegen... ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Mo 09.07.07 14:05 
Danke euch.
Ich habe mir das beispiel von dem User angeguckt und mal getestet, bzw. umgeschrieben, aber ich weiss nicht, wie ich vor dem = zeichen in einer Variable speichern kann, da ich am anfang keine zeichen drin habe um nach ihr zu suchen und dann zu übergeben.

MfG
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mo 09.07.07 14:12 
Zitat von Dunkel im oben verlinkten Thread:
Zitat:

ausblenden Delphi-Quelltext
1:
2:
OldString := ':Testwort,';
NewString := Copy(OldString, Pos(':', OldString), Pos(',', OldString));  // --> NewString = Testwort



Das ist die Antwort auf deine Frage.

Copy(Ausgangsstring, StartIndex, EndIndex)

Anstatt mit Pos() nach einem Index zu suchen kannst du natürlich auch einen festen Wert eingeben.

ausblenden Quelltext
1:
Copy(OldString, 1, 4);					


würde zum Beispiel alles vom Ersten bis zum vierten Zeichen kopieren...

Schau dir doch mal mit F1 die Delphi Hilfe zu Copy() an.

_________________
Delphi: XE - OS: Windows 7 Professional x64
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Mo 09.07.07 16:21 
Ah, jetzt habe ich das verstanden.
Ich habe das jetzt so gemacht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
s3 := ListBox1.Items[j];
str2 := Copy(s3, 1, Pos(' ', s3));
Delete(str2, Pos(' ', str2), Pos(' ', str2));
ListBox2.Items.Add(str2);


ich habe das noch mit Delete erweitert um am ande dieser eine Leerzeichen zu löschen, der noch mit drin ist.

Vielen Dank für die Hilfe.

MfG
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mo 09.07.07 17:07 
Um Leer- und Steuerzeichen am Anfang / Ende eines Strings zu entfernen kannst du auch

Trim(string)
TimLeft(string)
TrimRight(string)

verwenden.

_________________
Delphi: XE - OS: Windows 7 Professional x64
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Mo 09.07.07 18:27 
user profile iconHorschdware hat folgendes geschrieben:


Copy(Ausgangsstring, StartIndex, EndIndex)



Falsch! Du musst als dritten Parameter die Anzahl der zu kopierenden Zeichen angeben.

z. B.bla := 'test=string';
bla := Copy(bla, 1, pos('=', bla) - 1)


Kopiert vom ersten Zeichen bis zum = (-1, weil wir wollen das = ja nicht mit kopieren)

Da könnte man natürlich meinen das der letzte Parameter der "EndIndex" ist. Aber probier mal das hier aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
bla := 'test=string';
bla := copy(bla, 1, 4); //sollte "test" ergeben
bla2 := 'test=string';
bla2 := copy(bla2, 2, 4); //sollte "est=" ergeben


Bekommst du bei beiden Versionen den gleichen String?

Und damit wäre deine Frage auch gelöst :-)
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mo 09.07.07 20:13 
user profile iconAndreas L. hat folgendes geschrieben:
user profile iconHorschdware hat folgendes geschrieben:


Copy(Ausgangsstring, StartIndex, EndIndex)



Falsch! Du musst als dritten Parameter die Anzahl der zu kopierenden Zeichen angeben.



Meinte ich doch...
Nicht gleich hauen :-(

_________________
Delphi: XE - OS: Windows 7 Professional x64