Bold text element fails if there is a & symbol

4300
7
08-05-2015 06:49 AM
deleted-user-MS0lE1F_0-sy
Occasional Contributor

So I have a massive amount of data I need to get into a text element, so I wrote a python script for this.

textValue += "<BOL>" + row[0] + ": </BOL>" +  row[1]  + " - " + row[2] + '\r\n'

It works great.

     001: John Doe - 12345

     002: Jane Smith - 67890

The problem happens when a "&" symbol is introduced.

     <BOL>001:</BOL> John Doe - 12345

     <BOL>002:</BOL> Jeff & Jane Smith - 67890

I get that this is a formatting rule issue, but is there away I can get around this.   I guess I could write a script to replace all “&” with “and” but I prefer not to.  I appreciate any suggestions.

0 Kudos
7 Replies
TedKowal
Occasional Contributor III

Have you tried using ascii symbol value ...  chr(38)?

0 Kudos
deleted-user-MS0lE1F_0-sy
Occasional Contributor

Sorry for the confusion, it is not because I want the symbol, it is just that the symbol is already there in a lot of the attributes that I am trying to write to a text element.

0 Kudos
AnthonyAtkins1
New Contributor II

So what happens when you encounter the "&"? Is it a run-time error or a formatting error?  Since the character is already in the data the only thing I can think of is replacing it.

0 Kudos
deleted-user-MS0lE1F_0-sy
Occasional Contributor

It still runs fine, but the results of my list in the text element are <BOL>002:</BOL> Jeff & Jane Smith - 67890 instead of 002: Jeff & Jane Smith - 67890.  If there just 1 row that has the "&" the whole list will look like <BOL>002:</BOL> Jeff & Jane Smith - 67890.   It ignores the bold formatting altogether.  I think you are right I might have to just replace them, was hoping someone ran into this type a thing before and had a work around.  Thanks for the reply.

0 Kudos
IanMurray
Frequent Contributor

Instead of replacing with and, you can replace with it with "&amp;", which is read by the text formatter as an ampersand.  I made a duplicate field in my attribute table and replaced my "&" with "&amp;" and it labelled properly off the copy field.

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

deleted-user-MS0lE1F_0-sy
Occasional Contributor

Thanks for the tip!  This is exactly what I will do, if I do not find a way to do it without replacing.

0 Kudos
IanMurray
Frequent Contributor

further testing, you don't need to make a new field.

I replaced the value in the label expression then added it to the expression I wanted returned and it worked perfectly.

def FindLabel ([Test]):
  label = [Test].replace("&" , "&amp;")
  return "<BOL>" + label + "</BOL>"

This worked for a text field that had an ampersand on it.  John & Jim displayed correctly on a point with this expression.  Also I explored python string formatting and nothing worked on that front.