Autor Beitrag
ebs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 213

Suse Linux 9.2, Win 98, Win NT, Win XP, Win for Workgroups, Win XP SP2, Dos 6.1
D3 Prof, D2005 PE, Delphi 2006 Prof.
BeitragVerfasst: So 03.04.05 09:28 
Hallo!
Ich habe mal eine Frage zu Leerzeichen und Strings. Und zwar arbeite ich mit Strings, die Leerzeichen haben, die ich aber weghaben möchte. Ich kenne natürlich die Funktion trim, womit ich aber ja nur die Strings am Anfang und am Ende wegkriege, wobei ich aber alle Leerzeichen weghaben will. Gibt es da noch eine andere Möglichkeit?
Danke!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 03.04.05 09:33 
Guckst du hier
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: So 03.04.05 11:57 
durchwander den string doch mit einer schleife von hinten nach vorne und lösche alle zeichen, die ' ' sind.
etwas so:
ausblenden Delphi-Quelltext
1:
2:
for i := length(meinstring)-1 downto 0 do
  if meinstring[i] = ' ' then delete(meinstring,i,1);

_________________
[inspirationslos]
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 03.04.05 12:08 
der_zaehe das was ganz böses...
du kannst net auf nen string[0] zugreifen = AV

ausblenden Delphi-Quelltext
1:
2:
for i := length(meinstring) downto 1 do   
  if meinstring[i] = ' ' then delete(meinstring,i,1);


ausserdem gibbet ne replaceall funktion (heißt die so???) mit der man das einfacher machen kann

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 03.04.05 12:51 
Das heißt StringReplace. Da zeigt auch mein Link weiter oben hin. :wink:
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 03.04.05 13:08 
hab den noch nie verwendet ist bestimmt ziemlich langsam anstatt man eben ne forschleife macht ;>

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: So 03.04.05 13:27 
@uall@ogc:
dummer fehler von mir. ich vergess immer, das die erste stelle geschützt ist.

_________________
[inspirationslos]
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 04.04.05 07:19 
user profile iconuall@ogc hat folgendes geschrieben:
hab den noch nie verwendet ist bestimmt ziemlich langsam anstatt man eben ne forschleife macht ;>

Habe ich noch nicht geprüft. Wenn es in eine zeitkritische Routine eingebaut wird, kann man es ja prüfen. Ansonsten ist StringReplace eine praktische Sache.