Autor Beitrag
Flinthrc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 09.10.05 20:09 
Ich möchte einfach per Knopfdruck einen Text der in einem Textfeld steht durch bestimmte Zeichen ersetzen.

Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
begin
  S := Edit1.Text;
 
  //Leerzeichen in Nullen umwandeln
  while Pos('a', S) > 0 do
    S[Pos('a', S)] := '4';
  while Pos('A', S) > 0 do
    S[Pos('A', S)] := '4';
  while Pos('b', S) > 0 do
    S[Pos('b', S)] := 'ß';
  while Pos('B', S) > 0 do 

//  usw.

  showmessage(s);


Nur kann ich einen Buchstaben durch einen Buchstaben ersetzen. Ich möchte aber gern einen Buchstaben durch zwei Buchstaben ersetzen. Wie bekomme ich das hin?

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt.
-delphin-
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: So 09.10.05 20:36 
Sieht mir ziemlich nach Leetsprache aus.. Nunja..
Wie soll das denn aussehen mit 2 Buchstaben?
z.B. der Buchstabe ist A und du willst ihn durch xy ersetzen dann:
ausblenden Delphi-Quelltext
1:
2:
  while Pos('A', S) > 0 do
    S[Pos('A', S)] := 'xy';

So in etwa? =) Und warum nimmst du nicht If, statt While? oO

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 09.10.05 21:47 
Für solche Dinge nimmt man StringReplace ... Damit geht das um einiges schneller ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 09.10.05 22:57 
Hallo,
@user profile icon-delphin-: Seit wann geht das denn :gruebel:
ausblenden Delphi-Quelltext
1:
S[Pos('A', S)] := 'xy';					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 10.10.05 16:09 
Wie sieht das genau mit dem "StringReplace" aus? Fang erst mit Delphi an.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 10.10.05 16:11 
Wie wär's mit suchen?
Suche in der Entwickler-Ecke STRINGREPLACE();

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 10.10.05 16:40 
ausblenden Programm
1:
2:
3:
4:
5:
6:
7:
8:
9:
begin
  S :=Edit1.Text;
  //Leerzeichen in Nullen umwandeln

  S := StringReplace(S, 'a', ' THE ',[rfReplaceAll, rfIgnoreCase]);


  showmessage(S);
end;


Damit lässt sich aber nur ein Buchstabe ändern.
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Di 11.10.05 16:17 
Wie kann ich mehrere umwandeln?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 11.10.05 16:18 
Moin!

Dann mußt du die Funktion mit den gesuchten Buchstaben entsprechende oft aufrufen. :wink:

cu
Narses
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Di 11.10.05 18:21 
Das geht eben nicht!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 11.10.05 18:46 
Moin!

user profile iconFlinthrc hat folgendes geschrieben:
Das geht eben nicht!

Ist dein Delphi kaputt? :D

Bei mir geht das prima:
ausblenden Delphi-Quelltext
1:
2:
3:
S := StringReplace(S, 'ä', 'ae',[rfReplaceAll, rfIgnoreCase]); 
S := StringReplace(S, 'ö', 'oe',[rfReplaceAll, rfIgnoreCase]); 
S := StringReplace(S, 'ü', 'ue',[rfReplaceAll, rfIgnoreCase]);

cu
Narses
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mi 12.10.05 16:15 
Muss wohl ein Bug gewesen sein... Jetzt gehts! Danke