Arcade text formatting in labels does not work when an ampersand is in the string

529
2
Jump to solution
05-18-2022 12:33 PM
Labels (1)
LyonMNGIS
Occasional Contributor II

Hello,

I am using Arcade to format text for a label.  I noticed that  the labels do not format correctly when an ampersand is in the attribute that needs to be labeled.  For example "Aldi Inc" labels correctly. while "Quist Moving & Storage" does not label correctly.

Label String:

"<FNT name = 'Arial' style = 'Regular' size = '12'>" + $feature.RES_NAME + "</FNT>"

Please let me know how I can label strings with an & in them.

Thank You!

 

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

When I just use $feature.TextField, it works:

JohannesLindner_0-1652937691435.png

 

When I use the label style tags, ArcGIS probably switches to HTML, where ampersand is a special character, so the expression breaks in these features (your code):

"<FNT name = 'Arial' style = 'Regular' size = '12'>" + $feature.TextField + "</FNT>"

JohannesLindner_1-1652937803048.png

 

 

You have to escape the ampersand as an HTML entity:
"<FNT name = 'Arial' style = 'Regular' size = '12'>" + Replace($feature.TextField, "&", "&amp;") + "</FNT>"

JohannesLindner_2-1652938027261.png

 

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Regular Contributor

When I just use $feature.TextField, it works:

JohannesLindner_0-1652937691435.png

 

When I use the label style tags, ArcGIS probably switches to HTML, where ampersand is a special character, so the expression breaks in these features (your code):

"<FNT name = 'Arial' style = 'Regular' size = '12'>" + $feature.TextField + "</FNT>"

JohannesLindner_1-1652937803048.png

 

 

You have to escape the ampersand as an HTML entity:
"<FNT name = 'Arial' style = 'Regular' size = '12'>" + Replace($feature.TextField, "&", "&amp;") + "</FNT>"

JohannesLindner_2-1652938027261.png

 

 


Have a great day!
Johannes
RobertBorchert
Frequent Contributor III

The problem is the formatting you have.

Is there a reason why you use coded formatting and not simply specify font and size in the label properties?

0 Kudos