【delphi|Delphi的StringReplace】
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;
推荐阅读
- delphi|Delphi7程序调用C#写的DLL解决办法
- delphi|Delphi ServerSocket,ClientSocket示例
- C++|c++中string的模拟实现
- c++|c++的string类的模拟实现 以及basic_string::_M_construct null not valid错误的原因
- C++|[C/C++]详解STL容器1--string的功能和模拟实现(深浅拷贝问题)
- c++|模拟实现string类
- 语言|转(我的野蛮成长)
- Delphi|如何准备迎接新版本Embarcadero RAD Studio Delphi、C++Builder 11
- Delphi|RAD Studio Delphi C++ Builder 2020年11月开发路线图PPT(研发Delphi WebAssembly编译器)