我做了一个小函数,可以满足你的要求,你试试吧:
function substitute(s:string;c,r :char):string;
var
i :integer;
ret :string;
begin
i := pos(c,s);
ret := '';
while i<>0 do
begin
ret := ret+copy(s,1,i-1);
ret := ret+r;
s := copy(s,i+1,length(s));
i := pos(c,s);
end;
Result := ret+s;
end;
其中s是源字符串,c是要被替换的字符,r是更改后的字符.
自己做个替换函数
function TForm1.ReplaceChr(OldStr: String): String;
var J:integer;
NewStr:String;
begin
NewStr:='';
for J:=1 to Length(OldStr) do
begin
if copy(OldStr,J,1)='&' then
NewStr:=NewStr+'*'
else
NewStr:=NewStr+copy(OldStr,J,1);
end;
result:=NewStr;
end;