Delphi的StringReplace 字符串替换函数[delphi]

2016-08-22 10:23:39来源:http://shaojc85.blog.51cto.com/7511000/1619510作者:shaojc85人点击


原文来自: 【100脚本网 www.pc100.net】

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

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

For Example:

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


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台