Delphi的StringReplace 字符串替换函数
2013-10-19 02:34
295 查看
function StringReplace (const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
rfReplaceAll:全部替换
rfIgnoreCase:忽略大小写
For Example:
var
aStr: String;
begin
aStr := '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;
rfReplaceAll:全部替换
rfIgnoreCase:忽略大小写
For Example:
var
aStr: String;
begin
aStr := '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;
相关文章推荐
- delphi 选择目录对话框(SelectDirectory 函数)
- Delphi 选择文件夹对话框 (有新建文件夹按钮)修正版
- delphi中查找指定文件的例程
- delphi字符串操作函数一览
- Delphi Leftstr,Rightstr函数应用
- 在delphi中实现密码框“大写锁定打开”的提示
- Delphi 中PChar()函数的用法
- delphi Move操作
- DELPHI实现关闭指定进程,自身防杀
- (Delphi)New,Getmem,ReallocMem联系与区别(转)
- delphi xe2 string、AnsiString及Tbytes之间的转换
- Delphi XE5 Android 运行黑屏卡死的解决方法
- 【转】Delphi 文件拖放
- Delphi XE5 for Android (十一)
- Raknet 简单封装 For Delphi
- delphi的 ics的使用例子,ftp客户端上传的例子。
- Delphi 记事本 TMemo
- AutoIt.Delphi.示波表.一键软件全自动安装包生成器
- Delphi中取得程序版本号
- delphi 软件自动获取管理员权限方法