jhaughey Posted November 6, 2017 Share Posted November 6, 2017 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 Quote Link to comment Share on other sites More sharing options...
step Posted November 6, 2017 Share Posted November 6, 2017 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; Quote Link to comment Share on other sites More sharing options...
jhaughey Posted November 7, 2017 Author Share Posted November 7, 2017 Thanks for pointing me in the right direction. Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted October 17, 2018 Share Posted October 17, 2018 So if I wanted to make sure that all & display correctly, would I just enter the below for all fields? Var1 = ReplaceSubstring("&","&"); I'm running into the issue of users entering & and it being replaced with "&" and I'm not sure how to fix it. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 17, 2018 Share Posted October 17, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.