Autor Beitrag
p4nsen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Fr 21.11.03 08:55 
hab da mal folgende frage, wie kann ich mir die länge eines strings bis zum leerzeichen anzeigen lass??
z.b.
hugo geht spaziern.

mich interresiert nur die länge vom stringabschnitt "hugo" (also 4)
wie gestalte ich das syntaxmäßig??
mit pos() dachte ich schon aber *kA habs net hinbekomm
thx im voraus :roll:
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 21.11.03 09:23 
Titel: hmm,
wieso hast es mit POS nicht hin bekommen ?
ausblenden Delphi-Quelltext
1:
substring := COPY(gesamtstring,1,POS(' ',gesamtstring)-1);					

_________________
mfg. Joel
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Fr 21.11.03 09:24 
Hi p4nsen

Pos gibt die Position des Ersten gefundenen Substring zurück und beginnt bei seiner Zählung mit 1 (ErstesZeichen =1). Wenn du immer die Länge des ersten Wortes willst reicht das:
ausblenden Delphi-Quelltext
1:
Pos(' ',SuchStr)-1					


Wenn du nicht garantieren kannst, das einzweites wort existiert musst du noch "nicht finden" abfangen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if Pos(' ',SuchStr) = 0 then
  Ergebniss:=length(SuchStr)-1
else
  Ergebniss:=Pos(' ',SuchStr)-1;
p4nsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Fr 21.11.03 09:30 
oka thx für die schnellen antworten :P *freu*