Autor Beitrag
V!P3R
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Fr 11.01.08 16:58 
Hab Edit1 und Memo1

hab einen Button1 auf dem 'Umwandeln' steht.

wenn in edit1:'beispiel' steht soll delphi per Click auf button1 jeden buchstaben einzeln umwandeln und ins memo feld schreiben.

zum beispiel kommt dann raus: Memo1: 'cfjtqjfm' (jeder buchstabe um eins nach rechts verschoben im ABC)


wie kann ich das machen?


MfG
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Fr 11.01.08 17:00 
ausblenden Delphi-Quelltext
1:
2:
for ...
replace(...);

_________________
Die Lösung ist nicht siebzehn.
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Fr 11.01.08 17:02 
danke für die schnelle antwort,
aber wie sage ich jetzt das vom Edit1 Feld ins Memo1 Feld übertragen wird?

Wie muss der komplette Code (Muss ab buchstabe C natürlich nicht weiter aufgeschrieben werden)
für Button1.Click heißen?

ausblenden Delphi-Quelltext
1:
TEdit: Edit1					

ausblenden Delphi-Quelltext
1:
TMemo: Memo1					


Vielen Dank im Voraus


MfG


Zuletzt bearbeitet von V!P3R am Fr 11.01.08 17:17, insgesamt 1-mal bearbeitet
Kri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 118



BeitragVerfasst: Fr 11.01.08 17:16 
Hab das ganze in ASCII umgewandelt dann 1 dazu addiert und dann wieder zurückgewandelt..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var i,c:integer;
    s,u:string;
begin
for i:=1 to length(Edit1.Text) do //Zähler
 begin
  c:=ord(Edit1.Text[i]);          //Umwandlung in ASCII
  c:=c+1;                         //ASCII+1 (Nächster Buchtage, Zahl etc.)
  u:=chr(c);                      //Zurückwandlung
  s:=s+(u);                       //Neuen Buchtaben zum Alten schreiben
 end;
Memo1.Lines.Add(s);               //Neues Wort in Memo1 schreiben
end;


Gruß
Kri
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Fr 11.01.08 17:24 
Ja, vielen Dank. Code klappt wunderbar.

Nur... Ich würde gerne Selbstbestimmen was 'A' sein soll.

wenn ich zum beispiel will das 'A' = 'B' ist, aber 'B' = 'Y' (ist nur ein beispiel)

ich will aslo jeden einzelnen buchstaben bestimmen...

MfG
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: Fr 11.01.08 17:28 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
A := 'Alter Mann';
B := StringReplace(A, 'Alt', 'Jung', [rfReplaceAll]);
ShowMessage(B);
// Ausgabe: Junger Mann


EDIT: Einfache Lösung, siehe 4 Posts weiter unten.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)


Zuletzt bearbeitet von GTA-Place am Fr 11.01.08 17:43, insgesamt 2-mal bearbeitet
Kri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 118



BeitragVerfasst: Fr 11.01.08 17:30 
Dann ist es aber sehr umständlich..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var i:integer;
    u,s:string;
begin
for i:=1 to length(Edit1.Text) do
 begin
  if Edit1.Text[i]='A' then
   u:='B';
  if Edit1.Text[i]='B' then
   u:='Y';
  {................usw.............}
  s:=s+u;
 end;
Memo2.Lines.Add(s);
end;


Gruß
Kri
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: Fr 11.01.08 17:32 
Naja, da ist StringReplace einfacher als dutzend If-Abfragen.

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



BeitragVerfasst: Fr 11.01.08 17:34 
Hm ja stimmt scho..
Naa jedem dass seine..
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: Fr 11.01.08 17:39 
Ganz einfache Lösung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  Str: String;
  X:   Integer;
const
  B = Array[65..90] of String = ('X', 'P', 'D', ...);
begin
  Str := '';

  for X := 1 to Length(Edit1.Text) do
    Str := Str + B[Ord(Edit1.Text[X])];

  Memo1.Lines.Add(Str);
end;


Das Array representiert alle 26 Großbuchstaben in deiner gewünschten Ordnung. Sollen auch Kleinbuchstaben ersetzt werden, so musst du vorher noch überprüfen, ob der Buchstabe (Edit1.Text[X]) groß oder klein ist und dann auf das entsprechende Array zugreifen.

Großbuchstaben: 65..90
Kleinbuchstaben: 97..122
Zahlen: 48..75

Vgl.: ASCII-Tabelle

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)


Zuletzt bearbeitet von GTA-Place am Fr 11.01.08 17:41, insgesamt 2-mal bearbeitet
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 11.01.08 17:40 
user profile iconKri hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var i:integer;
    u,s:string;
begin
for i:=1 to length(Edit1.Text) do
 begin
  if Edit1.Text[i]='A' then
   u:='B';
  if Edit1.Text[i]='B' then
   u:='Y';
  {................usw.............}
  s:=s+u;
 end;
Memo2.Lines.Add(s);
end;

Das klappt nicht, da u schon 'b' ist, wenn der Wert auf 'b' überprüft wird, aber ursprünglich 'a' war.
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: Fr 11.01.08 17:42 
@Yogu: Kri liest den Buchstaben nochmal aus dem Edit aus, das klappt schon ;-)

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



BeitragVerfasst: Fr 11.01.08 17:45 
Doch funktioniert doch wunderbar, da ich jeden Buchstaben einzeln Anspreche.. oder verstehe ich jetzt was falsch..
Sorry @GTA habs net gesehn dass du schon geantwortet hast

Gruß
Kri
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Fr 11.01.08 19:47 
Ich hab das jetzt so gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for i:=1 to length(E1.Text) do
 begin

  if E1.Text[i]='A' then  u:='A';
  if E1.Text[i]='B' then  u:='B';
  //...


Wenn ich aber
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for i:=1 to length(E1.Text) do
 begin

  if E1.Text[i]='Ab' then  u:='A';
  if E1.Text[i]='Bau' then  u:='B';
  //...


dann gehts nicht mehr.( bzw. es passiert gar nicht wenn wan 'Ab' versucht umzuwandeln).

warum?
wie kann man das ändern/umgehen?


MfG
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: Fr 11.01.08 19:54 
Mit StringReplace. Du kannst nicht auf einen Buchstaben [i] zugreifen und ihn auf 2 Buchstaben überprüfen.

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

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 11.01.08 22:46 
Mit String[i] greifst du auf eine Variable des Typs CHAR zu.
diese kann nur EIN Zeichen enthalten. Deshalb Char.

'ab' ist vom Typ String (Eine eindimensionales Array von Chars).

Also kannst du 'ab' nicht in einen Char schreiben.

=> Ergo StringReplace verwenden!

lG Green
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: So 13.01.08 12:00 
Vielen Dank für ALLE antworten., ich habe StringReplace UND die ASCII Umwandlung von Kri genutzt.

Und das mit dem
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for i:=1 to length(E1.Text) do
 begin

  if E1.Text[i]='A' then  u:='A';
  if E1.Text[i]='B' then  u:='B';
  //...

ist auch mir jetzt kla geworden, warum das nicht geht. :) vielen dank an GTA-Place und Green

Vielen Dank an alle

MfG V!P3R