1

I am using the following expression in an ArcGIS feature label:

"(CH<SUB>4</SUB> " + $feature.Methane + " ppm)"

This works (e.g., CH4 15 ppm) unless the $feature.Methane value is "<1". In that case the result is

CH<SUB>4</SUB> <1 ppm

How do I get around this?

1
  • You have to HTML encode < to prevent it from being interpreted as an HTML control character. Try: "(CH<SUB>4</SUB> " + Replace($feature.Methane,"<","&lt;") + " ppm)"
    – bixb0012
    Commented Nov 11, 2022 at 16:02

2 Answers 2

1

Some symbols such as <, > and " must be encoded similar to how it's done in XML or HTML. So rather than just typing the actual character, use &lt;, &gt; and &quot;

In your example:

CH<SUB>4</SUB> &lt;1 ppm

lt stands for lesser than, gt for greater than

0

When using Arcade for labeling, the output is interpreted as HTML. In this case, the HTML reserved character < is in the field value, and its presence is messing up the HTML interpretation and display of the field value.

Knowing that Arcade labeling is interpreted as HTML, one can create a label expression that encodes the HTML reserved characters to their appropriate HTML entity.

var htmlEncode = Dictionary(
    '"', "&quot;",
    "'", "&apos;",
    "&", "&amp;",
    "<", "&lt;",
    ">", "&gt;",
);

var rawString = "Value <1 or >5.  It's me.";

for(var char in htmlEncode) {
    rawString = Replace(rawString, char, htmlEncode[char]);
};

return rawString

returns

Value &lt;1 or &gt;5.  It&apos;s me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.