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

百般思念 提交于 2020-07-04 02:53:18

问题


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:

substring - > newstring
substring, -> newstring
substring123 -> substring

回答1:


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.


来源:https://stackoverflow.com/questions/25852384/is-there-any-function-procedure-as-replacestring-but-for-whole-words-on-delphi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!