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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

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

dgopois
12-Amethyst

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

1 ACCEPTED SOLUTION

Accepted Solutions
RickSchoen
5-Regular Member
(To:dgopois)

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.

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 🙂

Thank you again for your help

 

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

Thank you again for your help

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

RickSchoen
5-Regular Member
(To:dgopois)

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

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

 

Rick

dgopois
12-Amethyst
(To:RickSchoen)

Hello Rick,

 

Thank for your solution.

It works.

Top Tags