LabelExpressionInfo with single quotes does not show labels

256
1
Jump to solution
07-26-2023 08:57 AM
platmoskito
New Contributor II

I want to assign a labelexpressioninfo to a labelclass for a featurelayer that may contains single apostrophes. However, these labels appear to interfere with the arcade expression construction. How can I get the label to appear? Escaping the character does not help either.

codepen demonstration issue with label "Bob's":

https://codepen.io/coxfsi/pen/KKrGNbj?editors=1000

example:

        const name = "Bob's";
        const labelClass = {
          // autocasts as new LabelClass()
          symbol: {
            type: "text", // autocasts as new TextSymbol()
            color: "green",
            backgroundColor: [213, 184, 255, 0.75],
            borderLineColor: "green",
            borderLineSize: 1,
            yoffset: 5,
            font: {
              // autocast as new Font()
              family: "Playfair Display",
              size: 12,
              weight: "bold"
            }
          },
          labelPlacement: "above-center",
          labelExpressionInfo: {
            expression: `'${name}'`
          }
        };

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

If working with a literal, you must "double escape" the apostrophe:

const name = "Bob\\'s";
//etc
labelExpressionInfo: {expression: `"${name}"`}

 

Otherwise, you'll need to do the escaping in the expression itself:

const name = "Bob's";
//etc
labelExpressionInfo: {expression: `Replace("${name}", "'", "\'")`}

 

View solution in original post

1 Reply
JoelBennett
MVP Regular Contributor

If working with a literal, you must "double escape" the apostrophe:

const name = "Bob\\'s";
//etc
labelExpressionInfo: {expression: `"${name}"`}

 

Otherwise, you'll need to do the escaping in the expression itself:

const name = "Bob's";
//etc
labelExpressionInfo: {expression: `Replace("${name}", "'", "\'")`}