我正在爲其他人替換字母,問題是它不能按我的需要工作。在delphi中替換的函數
來源
function encode(texto:string): string;
var
cadena: string;
i: integer;
const
letras: array [1 .. 26] of string = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z');
const
in_letras: array [1 .. 26] of string =
('z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l',
'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a');
begin
for i := Low(letras) to High(letras) do
begin
texto := StringReplace(texto, letras[i], in_letras[i],[rfReplaceAll]);
end;
Result := texto;
end;
Edit2.Text := encode(Edit1.Text);
使用函數編碼()返回EDIT1和我Edig1,這是不應該的,因爲我做錯了什麼,當替換功能
您不能替換字符這樣。考慮如果您替換例如'd' - >'w',然後通過該迭代轉到'w'。它已經把'w'改回到'd'。 – TLama
或者你需要使用第二個字符串(與傳入變量不同),然後將其分配給結果。 –