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!
Solved! Go to Solution.
When I just use $feature.TextField, it works:
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>"
You have to escape the ampersand as an HTML entity:
"<FNT name = 'Arial' style = 'Regular' size = '12'>" + Replace($feature.TextField, "&", "&") + "</FNT>"
When I just use $feature.TextField, it works:
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>"
You have to escape the ampersand as an HTML entity:
"<FNT name = 'Arial' style = 'Regular' size = '12'>" + Replace($feature.TextField, "&", "&") + "</FNT>"
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?
The HTML entity for "<" is "<"
"<CLR red='255'>" + $feature.Bla + TextFormatting.NewLine + Replace($feature.Bla, "<", "<") + "</CLR>"
I just posted this Idea to do those replacements behind the scenes. Go lend your support to it to hopefully solve this problem in future ArcGIS Pro versions.
I'm guessing the answer is no but it'd be great if regular HTML and CSS worked with Arcade so labels could mix and match color and italics etc to text. Kind of like how you inline format text in text boxes in ArcMap and Pro. Also would be great if popups supported full HTML/CSS. (instead the measly 10 tags or so, and perhaps MOST importantly, how they don't support the <title> tooltip tag, I have been begging for for 15 years) Basically it'd be great if standard HTML was supported across the platform (Pro, Map Viewer, Popups, Smart Forms in Survey123/Field Maps, etc)