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}'`
}
};
Solved! Go to Solution.
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}", "'", "\'")`}
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}", "'", "\'")`}