简单的字符串操作?~(50分)

  • 主题发起人 动感超人
  • 开始时间

动感超人

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么能把一个字符串里的一个同类字符都替换为其他字符
类入
把Str:=‘AbcdAbcd’里的A替换为‘Q’ (Str:=‘QbcdQbcd")
 
1.自己写 用pos
2.查以前的贴子
 
不知道有没有这样的函数。
procedure TForm1.Button1Click(Sender: TObject);
var
str,new:string;
i:word;
begin
str:='AbcdAbcd';
new:='';
for i:=1 to length(str) do
begin
if str='A' then
str:='Q';
new:=new+str;
end;
showmessage(new);
end;
 
StringReplace函数应该可以
type
TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
function
StringReplace(const S, OldPattern, NewPattern: string;
Flags: TReplaceFlags): string;
 
to xuxincheng大侠:
TReplaceFlags是怎样定义的?help查不到
to 动感超人:分不要了,给楼上吧
 
type
TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
function StringReplace(const S, OldPattern, NewPattern: string;
Flags: TReplaceFlags): string;
全部替换 stringReplace(s,s1,[rfReplaceAll]);
 
谢谢,这个stringReplace挺好用
我在sysuntils也查到了。
 
多人接受答案了。
 
顶部