Is there any function/procedure as ReplaceString but for whole words on Delphi?

后端 未结 1 582
遥遥无期
遥遥无期 2021-01-24 04:30

Is there any function/procedure as ReplaceString but for whole words on Delphi? I just need to replace substring to the new one when it\'s a whole word. For example

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 05:07

    You can use the built-in regex library to do this. For example:

    {$APPTYPE CONSOLE}
    
    uses
      System.RegularExpressions;
    
    const
      InputString = 'a Substring, substring123, some more text';
    
    begin
      Writeln(TRegEx.Replace(InputString, '\bsubstring\b', 'newstring', [roIgnoreCase]));
    end.
    

    0 讨论(0)
提交回复
热议问题