I am currently working on a translation project. One of the problems that I have encountered is when I try to replace special character characters.
For example:
[Animal] can be furry. Dog is an [Animal].
I need to replace [Animal] with Animal . Please note that I only need to replace the entire word. Thus, the result should be as follows:
Animal can be furry. Dog is an Animal.
In addition, as I said, it should be a whole word. Therefore, if I have:
[Animal][Animal][Animal] can be furry. - the result should be
[Animal][Animal][Animal] can be furry. - nothing happened because [Animal] does not match [Animal][Animal][Animal]
Example:
string originalText1 = "[Animal] can be furry"; string badText ="[Animal]"; string goodText = "Animal"; Regex.Replace(originalText1, Regex.Escape(badText), Regex.Escape(goodText));
Everything is good. But, as I said, I need the whole word to be replaced. And with the code above, " [Animal]can be furry " will be replaced with " Animalcan be furry ", which is no no.
so i also tried:
Regex.Unescape( Regex.Replace( Regex.Escape(originalText1), String.Format(@"\b{0}\b", Regex.Escape(badText)), Regex.Escape(goodText)))
However, this will not work. And now I'm lost. Please, help.
I would also like to mention that there was the FIRST similar post, but this question did not require replacing the whole word. I scanned the network for almost 3 hours to no avail. Your help will be greatly appreciated. Thanks!