0

I'm using this example to replace a string in a file. Works fine replacing all matching strings (also recognizes sensitive case). Now i'm need that it can replace a string only if not contains in another string, for example:

  • UserName - Change only here
  • GetUserName - Not change here

How make (utilizing the same code)?

FLASHCODER
  • 1
  • 7
  • 24
  • You want to "match whole words". (Because surely you want to replace "UserName" even if it is contained inside a larger string "The variable is named UserName today.".) In other words, you want to replace an instance of the search phrase iff it is a word in the string, and not strict substring of a word. – Andreas Rejbrand Apr 11 '20 at 13:46
  • 3
    Have you seen https://stackoverflow.com/questions/25852384/is-there-any-function-procedure-as-replacestring-but-for-whole-words-on-delphi and https://stackoverflow.com/questions/1678572/is-there-an-efficient-whole-word-search-function-in-delphi/1678814#1678814 ? – Andreas Rejbrand Apr 11 '20 at 13:48
  • 1
    Use a regex for this – David Heffernan Apr 11 '20 at 14:40

0 Answers0