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

1601
5
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 Frequent 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

5 Replies
JohannesLindner
MVP Frequent 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
JackiBergman
New Contributor II

I'm having the same issue with <. I would like to show the GW elevation as <766.44 ft.

0 Kudos
JohannesLindner
MVP Frequent Contributor

The HTML entity for "<" is "&lt;"

"<CLR red='255'>" + $feature.Bla + TextFormatting.NewLine + Replace($feature.Bla, "<", "&lt;") + "</CLR>"

Have a great day!
Johannes
0 Kudos
JohannesLindner
MVP Frequent Contributor

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.


Have a great day!
Johannes
0 Kudos