`
netfork
  • 浏览: 480464 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Delphi的StringReplace

阅读更多
您使用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 ,高效率,秒杀 原版

    Delphi字符串快速替换函数,速度超快 秒杀自带的StringReplace函数

    Delphi自带的StringReplace效率非常低,字符串长一些就很慢。这个速度绝对快,你可以和StringReplace比一下,

    Delphi fast Pos & StringReplace:搜索/替换(ansi)字符串,区分大小写,32 位和 64 位-开源

    单元 StrPosDefs 和 StrPos32 和/或 StrPos64 包含扩展 system.pos 和 sysUtils.StringReplace 功能的函数,它们可能会导致显着的性能改进。 功能: • (重复)字符串中子字符串的位置(ANSI 字符串或字符串),...

    JsonToClientDataSet

    jsonSrc := StringReplace(jsonSrc, '[', '', [rfReplaceAll, rfIgnoreCase]); jsonSrc := StringReplace(jsonSrc, ']', '', [rfReplaceAll, rfIgnoreCase]); jsonSrc := StringReplace(jsonSrc, '"', '', ...

    delphi _获取Internet时间

    unit GetInternetTime; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ... datetxt := StringReplace(datetxt, 'GMT', '', []); datetxt := Trim(datetxt);

    delphi通用函数单元一

    function Replace(Str,s1,s2:string;CaseSensitive:Boolean):string; {测试通过} {* 返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作} {example: replace('We know what we want','...

    delphi中如何读取有逗号分割符数据

    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 : ...

    ASCIICoder2

    新增加1个老外汇编写的单元FReplace.pas,以取代delphi自带的StringReplace太慢的问题,需采用FastReplace函数. 可以将16进制数据直接存为bin文件(点右键之类的出来),以便可以直接将看见的HexStr存为数据,例如...

    Delphi6函数大全

    Delphi6函数大全 首部 function AnsiReplaceStr(const AText, ...参考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags 例子 Edit4.Text := AnsiReplaceStr(Edit1.Text, Edit2.Text, Edit3.Text);

    Delphi网络公用函数

    procedure StrSimple_ReplaceString(var S: string; const Substr: string; index, Count: Integer); //去掉S中的回车返行符 procedure StrTruncateCRLF(var S: string); //判定S是否以回车返行符结束 ...

    DELPHI文本整理器

    // Memo1.Text := StringReplace(Memo1.Text, #13#10#13#10, #13#10, [rfReplaceAll]); { //无法撤销 //空行的去掉 //本行只有空格的也去掉 //全选 //复制到剪切板上 } procedure TStringFunction....

    《Delphi高级辅助工具精解》PDF版

    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, ...

    RxLib控件包内含RxGIF,全部源码及DEMO

    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 ...

    Acro Multi-Language Suite for Delphi Win32 4.0.11.2511(1)

    2、增加对Delphi XE的支持。 3、按命名管理,把Acro改为acro 4、修正DDManager,在cell中输入空白的DDKey后,离开改行,然后再也不能修改改行的DDKey,也不能取消,只能强制退出的问题。 5、为了尽量不引入不...

    rx第三方控件

    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 ...

    Senfore_DragDrop_v4.1

    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: ...

    madCollection 2.5.6.0 安装版(无源码)

    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 ...

    VclZip pro v3.10.1

    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 ...

Global site tag (gtag.js) - Google Analytics