您使用StringReplace這個funciotn試試看。
type
TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
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 自带 StringReplace 慢, 替换 StringReplace ,高效率,秒杀 原版
Delphi自带的StringReplace效率非常低,字符串长一些就很慢。这个速度绝对快,你可以和StringReplace比一下,
单元 StrPosDefs 和 StrPos32 和/或 StrPos64 包含扩展 system.pos 和 sysUtils.StringReplace 功能的函数,它们可能会导致显着的性能改进。 功能: • (重复)字符串中子字符串的位置(ANSI 字符串或字符串),...
jsonSrc := StringReplace(jsonSrc, '[', '', [rfReplaceAll, rfIgnoreCase]); jsonSrc := StringReplace(jsonSrc, ']', '', [rfReplaceAll, rfIgnoreCase]); jsonSrc := StringReplace(jsonSrc, '"', '', ...
unit GetInternetTime; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ... datetxt := StringReplace(datetxt, 'GMT', '', []); datetxt := Trim(datetxt);
function Replace(Str,s1,s2:string;CaseSensitive:Boolean):string; {测试通过} {* 返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作} {example: replace('We know what we want','...
sList.Text:=StringReplace(Astring,Dlmter,#13#10,[rfReplaceAll]); if (nPos>0) and (sList.Count>=nPos) then Result:=sList[nPos-1]; end; procedure TForm1.Button1Click(Sender: TObject); var str : ...
新增加1个老外汇编写的单元FReplace.pas,以取代delphi自带的StringReplace太慢的问题,需采用FastReplace函数. 可以将16进制数据直接存为bin文件(点右键之类的出来),以便可以直接将看见的HexStr存为数据,例如...
Delphi6函数大全 首部 function AnsiReplaceStr(const AText, ...参考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags 例子 Edit4.Text := AnsiReplaceStr(Edit1.Text, Edit2.Text, Edit3.Text);
procedure StrSimple_ReplaceString(var S: string; const Substr: string; index, Count: Integer); //去掉S中的回车返行符 procedure StrTruncateCRLF(var S: string); //判定S是否以回车返行符结束 ...
// Memo1.Text := StringReplace(Memo1.Text, #13#10#13#10, #13#10, [rfReplaceAll]); { //无法撤销 //空行的去掉 //本行只有空格的也去掉 //全选 //复制到剪切板上 } procedure TStringFunction....
1-4-12 Replace Components(组件替换工具) 1-4-13 Component Grid(组件网格) 1-4-14 Components To Code(产生组件的代码) 1-4-15 Editor Experts(编辑器专家) 1-5 GExperts的配置环境 1-5-1 File Location...
AnsiString(StringReplace(URLA, #13#10, '', [rfReplaceAll])), AnsiString(ExtractFilePath(ParamStr(0)) + '1.bmp'), //输出地址 StrtoIntDef('2', 2), //边界 StrToIntDef('5', 3), //大小 0, 1, 0, 0, ...
replace the BDE with some other 3rd party database engines (only for Delphi 3.0 or higher). TRxCheckListBox is a list box with built-in check boxes. TRxSpeedButton provides you more features than ...
2、增加对Delphi XE的支持。 3、按命名管理,把Acro改为acro 4、修正DDManager,在cell中输入空白的DDKey后,离开改行,然后再也不能修改改行的DDKey,也不能取消,只能强制退出的问题。 5、为了尽量不引入不...
replace the BDE with some other 3rd party database engines (only for Delphi 3.0 or higher). TRxCheckListBox is a list box with built-in check boxes. TRxSpeedButton provides you more features than ...
Delphi 6, DragDropD5.dpk for Delphi 5, DragDropC5.bpk for C++ Builder 5, etc. 4) Add the Drag and Drop Component Suite components directory to your library path. 5) Load the demo project group: ...
Case/switch jump tables are automatically detected and handled correctly. <br>The package "madExcept" was exactly build for that purpose, namely to replace Delphi's standard exception handling ...
These allow you to replace the standard pkzip encryption with your own. Data is passed to these events a buffer at a time. Use this with care as this is still somewhat experimental and I'm not sure ...