Skip to main content
Dec 16, 2022 2:04 PM UTC
Solved

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

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

Dec 20, 2022 2:44 PM UTC

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

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

 

Rick

7 replies

Dec 19, 2022 10:12 PM UTC

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.

dgopoisAuthor
Dec 20, 2022 9:31 AM UTC

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

 

Dec 20, 2022 10:34 AM UTC

Yes, sorry I hadn't tried. Does escaping the ampersand help?

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

BTW that looks like S1000D bike data 🙂