Select to view content in your preferred language

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

2972
6
Jump to solution
05-18-2022 12:33 PM
Labels (1)
LyonMNGIS
Frequent Contributor

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 Alum

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

6 Replies
JohannesLindner
MVP Alum

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
Honored Contributor

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
Emerging Contributor

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

0 Kudos
JohannesLindner
MVP Alum

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 Alum

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
Kevin_MacLeod
Frequent Contributor

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)

0 Kudos