Jump to content

Ampersand problem


jhaughey

Recommended Posts

Been banging my head against the wall trying to resolve an issue with ampersands. Our client is creating a business card through Marcom which has an ampersand. The filed in question is also being forced to upper case. Usually we would create a rule with the code:

 

if(CaseSelection == "allcaps")

Var1 = ReplaceSubstring("Title","&","&");

Var1 = ToUpper(Field(Var1));

return Var1

 

And that mostly works. Except that in this case the client is entering text that does not have spaces before and after the ampersand, and this is breaking.

 

When I check the "Treat as Tagged Text" box, the ampersand disappears. When I uncheck it I get the HTML "&" instead. I've looked at other threads here on similar topics, but have not been able to get anything to work.

 

Any advice?

 

Thanks,

John

Link to comment
Share on other sites

Usually we would create a rule with the code:

Var1 = ReplaceSubstring("Title","&","&"); 

This line of code isn't necessary. It is replacing every occurrence of "&" in the string "Title" with "&." Since there are no instances of "&" in "Title," you can remove that code.

 

I'm going to assume instead that you want to replace all instances of "&" in a field named "Title" with an ampersand. I think this will do what you want:

var title = RawTextFromTagged(Field("Title"));
if (CaseSelection == 'allcaps')
 title = ToUpper(title);
return title;

Link to comment
Share on other sites

  • 11 months later...
This line of code isn't necessary. It is replacing every occurrence of "&" in the string "Title" with "&." Since there are no instances of "&" in "Title," you can remove that code.

 

I'm going to assume instead that you want to replace all instances of "&" in a field named "Title" with an ampersand. I think this will do what you want:

var title = RawTextFromTagged(Field("Title"));
if (CaseSelection == 'allcaps')
 title = ToUpper(title);
return title;

In this case, if the field has no actual markup tags in it, you may want to use the UntaggedDataField function:

UntaggedDataField

var title = UntaggedDataField("Title");
if (CaseSelection == 'allcaps')
 title = ToUpper(title);
return title;

Like its sibling TaggedDataField, UntaggedDataField figures out whether the data field value is already tagged or not, and handles it appropriately.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...