除Delphi上的整个单词外,是否有任何函数/过程作为ReplaceString? [英] Is there any function/procedure as ReplaceString but for whole words on Delphi?

查看:86
本文介绍了除Delphi上的整个单词外,是否有任何函数/过程作为ReplaceString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何函数/过程,如 ReplaceString ,但对于Delphi上的整个单词呢?我只需要在整个单词替换掉新的子字符串。例如:

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


推荐答案

您可以使用内置的正则表达式库来做这个。例如:

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.

这篇关于除Delphi上的整个单词外,是否有任何函数/过程作为ReplaceString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆