cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

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

dgopois
13-Aquamarine

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

ACCEPTED SOLUTION

Accepted Solutions

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

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

 

Rick

View solution in original post

7 REPLIES 7

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.

dgopois
13-Aquamarine
(To:GarethOakes)

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

 

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

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

BTW that looks like S1000D bike data 🙂

dgopois
13-Aquamarine
(To:GarethOakes)

Thank you again for your help

 

I have tried with the escaping character, but the result is always incorrect.

dgopois
13-Aquamarine
(To:GarethOakes)

Thank you again for your help

I have tried with the escaping character, but the result is always incorrect.

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

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

 

Rick

dgopois
13-Aquamarine
(To:RickSchoen)

Hello Rick,

 

Thank for your solution.

It works.

Announcements

Top Tags