Autor Beitrag
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Mo 15.08.05 21:55 
hmm ich wollt mal einfach ein paar buchstaben gegen ein paar wörter austauschen.
also jeden buchstaben durch ein wort.

aber mein problem...
wenn ich jetzt zum beispiel bei dem word

mofa

das o durch hallo ersetze

dann hätte ich ja
mhallofa...aber wenn ich jetzt das a durch tschuess ersetze, dann habe ich ja 2 a's, die ich ersetzen muss.

aber ich möchte halt immer nur vom ausgangswort etwas verändern.
hoffe das war halbwegs verständlich
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Mo 15.08.05 21:58 
Dann mach's besser anders: Wenn es wirklich immer nur ein "Char" ist, das ersetzt werden soll, dann mach's mit einem "case", gehe den Quellstring Zeichen für Zeichen durch, setze den Zielstring zusammen - entweder aus den Ersatz-Strings, oder durch das Originalzeichen, wenn es keinen Ersatz gibt.
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Mo 15.08.05 22:00 
also um nen umweg komm ich nicht herum oder?
kannst du ein kleines beispiel geben mit dem case?
so ganz hab ichs noch nich verstanden
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Mo 15.08.05 22:05 
Mit deinem Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
ZielString := '';
for Index := 1 to Length(QuellString) do begin
  case QuellString[Index] of
    'a': ZielString := ZielString + 'tschuess';
    'o': ZielString := ZielString + 'hallo';
  else
    ZielString := ZielString + QuellString[Index]
  end;
end;
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Di 16.08.05 00:18 
Oder einfach Rückwärts. Wenn Du statt eines Buchstabens ein Wort einfügst an der STelle, dann sind die eventuell neuen Buchstaben, die aber nicht ersetzt werden sollen weiter hinten im String, sodass bei absteigendem IUndex diese nicht mehr erfasst werden.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
For i:=length(mystring) downto 1 do begin
    case mystring[i] of 
    'a':begin delete(mystring,i,1);insert('hallo',mystring,i);
    ....
    end;
end;
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Di 16.08.05 12:01 
naja danke, habs jetzt so gemacht wie Ligh gesagt hat