Autor Beitrag
Der-DeeJay
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 11.12.03 21:18 
HI

Ich Habe mal eine sicherlich sehr noob mäsige frage aber wie kann ich einen String nur bis zum ersten leerzeichen in einer variablen speichern???
so das es so aussieht??

Text: "Hallo ihr alle"

und im string soll nur "Hallo" stehen.

Wie macht man sowas???
Ich hoffe mir kann jemand helfen!!

MFG

Der-DeeJay
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 11.12.03 21:20 
Suche in: Delphi-Forum, Delphi-Library COPY
Suche in: Delphi-Forum, Delphi-Library POS

Aber du kommst besser weg, wenn du dir diese beiden Befehle mal in der Delphi-Hilfe anschaust. ;)
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Do 11.12.03 21:22 
Willkommen im Delphi-Forum! :welcome:

Zu deinem Problem: du suchst einfach nach dem ersten Leerzeichen, speicherst die gefunde Position in einer variable und löscht dann einfach die Textteile nach diesem Leerzeichen. Die Funktionen, die du dafür brauchst, heißen Suche in: Delphi-Forum, Delphi-Library POS und Suche in: Delphi-Forum, Delphi-Library DELETE. Folge einfach den Links, oder schau in der Delphi-Hilfe. :)

P.S.: Du kannst auch mal nach Copy suchen. Damit kann man das auch machen.

_________________
Viele Grüße
Jakob
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 11.12.03 21:30 
Und wenn man es von hand machen will, nimt man eine for-Schleife und testet jedes Zeichen mit if, ob es sich um ein Leerzeichen handelt. dabei kann man auch gleich kopieren.
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Do 11.12.03 21:32 
JO, kann man auch, kommt aber darauf an, wo das erste Leerzeichen ist :wink: Mit ner For-Schleife dauert das ggf. etwas länger.

_________________
Viele Grüße
Jakob
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 12.12.03 09:48 
Titel: hmm,
ausblenden Quelltext
1:
st := COPY(trim(st),1,POS(' ',trim(st))-1);					

_________________
mfg. Joel
focus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

XP, 2k, 98, Me
D6 Prof
BeitragVerfasst: Fr 12.12.03 09:52 
straight forward...da würd ich erst garnicht mit pos und sonstigem geraffel anfangen...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
 
==>SPACE = 0x20
==>ZERO  = 0x00

  topic=pC;
  while((^pC<>LZERO)and(^pC<>SPACE))Inc(pC); //read topic (exclude following waste)
  if(^pC<>LZERO) ^pC=LZERO;      //terminate topic

pc und topic sind jeweils zeiger auf zeichenketten, wobei in der zeichernkette (mit NULL terminiert) auf die topic zeigt nacher dein extrahierter begiff steht

Gruss
Michael

_________________
Wer im Leben kein Ziel hat, verläuft sich.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 12.12.03 10:32 
@focus: sehr schön.. damit schreibst du ein Nullzeichen in deinen String und terminierst ihn damit. Aber der ganze restliche String dahinter bleibt trotzdem erhalten und der entsprechende Speicherplatz auch reserviert! Die richtige Methode wäre also mit Copy oder Delete arbeiten, wobei Delete besser ist, da dieses nur den String direkt verändert während Copy einen neuen String erstellt der dann nur der alten String-Variable zugewiesen wird...!

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Der-DeeJay Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Fr 12.12.03 14:45 
Danke Leute nu kann ich auch weiter machen!!!

Ihr wart sehr hilfreich!!!!

MFG

Der DeeJay
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 12.12.03 15:43 
SetLength ginge auch noch:
ausblenden Delphi-Quelltext
1:
2:
3:
szStr := 'Hallo ihr alle';
if pos(#32,szStr) > 0 then
  SetLength(szStr,pos(#32,szStr)-1);