Skip to main content
13-Aquamarine
December 16, 2022
Solved

Using ACL, How to replace the string "and" by the character ampersand (&)

  • December 16, 2022
  • 1 reply
  • 3425 views

Hello,

I try to use the ACL function "gsub" to replace the string "and" by the character ampersand (&). But the replacement fails. Do you have a solution ?

David

Best answer by RickSchoen

Try this: gsub("and", "\\&", "Mk1 and Mk9")

We use similar substitutions frequently in our customizations for Arbortext Editor.

 

Rick

1 reply

16-Pearl
December 19, 2022

I haven't tried but I suspect you need to replace "and" with "&" or "&" because the ampersand character by itself is not permissible in XML. It is a special symbol for the XML parser.

dgopois13-AquamarineAuthor
13-Aquamarine
December 20, 2022

Hello,

 

Thanks for your response.

 

I try your solution but it doesn't work.

The result of the command:

sub("and", "&amp", "Mk1 and Mk9")

is "Mk1 andamp; Mk9"

 

In the documentation of the "sub" function: we can read:

If the replace string contains a “&” or “\0”, then it is replaced with the substring that matched regexpr.

 

David

 

10-Marble
December 20, 2022

Try this: gsub("and", "\\&", "Mk1 and Mk9")

We use similar substitutions frequently in our customizations for Arbortext Editor.

 

Rick