Delphi的StringReplace 字符串替换函数

2016-08-22 10:22:52来源:http://tayjq.blog.51cto.com/6314147/1168748作者:tayjq人点击


function StringReplace (const S, OldPattern,NewPattern: string; Flags: TReplaceFlags): string;


rfReplaceAll:全部替换
rfIgnoreCase:忽略大小写


For Example:


var
aStr:String;
begin
aStr := 'This is a book, not apen!';
ShowMessage(StringReplace (aStr, 'a', 'two',[]));//This is two book, not apen!只替换了第一个符合的字
ShowMessage(StringReplace (aStr, 'a', 'two',[rfReplaceAll]));//This is two book, not twopen!替换了所有符合的字
aStr := 'This is a book, not Apen!';
ShowMessage(StringReplace (aStr, 'a', 'two',[rfReplaceAll]));//This is two book, not Apen!只替换了符合的字(小写a)
ShowMessage(StringReplace (aStr, 'a','two', [rfReplaceAll, rfIgnoreCase]));//This is two book, not twopen!不管大小写替换了所有符合的字
end;


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台