Select to view content in your preferred language

Remove spaces from labels when using expressions

268
2
02-06-2026 03:36 AM
JamesCarroll7
Occasional Contributor

Hi all,

I'm trying to label some features with data from various columns in the attribute table. I've been using VBScript to do this, with an expression such as:

[Column 1] &vbnewline& [Column 2] &vbnewline& [Column 3] &vbnewline& etc.

The problem I'm encountering is if one of the columns is empty or has a null value, the label skips a line where that columns label should be (see screenshot). 

JamesCarroll7_0-1770377655505.png

Is there a way to remove this space? This is my first time using expressions to display labels in this way, so I'm relatively unfamiliar with VPScript, Arcade etc.

 

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

In Arcade, you can check whether a field is empty before adding it to the string.

This example uses an array (fields) that contains the field name of each of your fields (line 2). The code loops through that array (line 4) and adds the value to an array (output) if the field's value is not empty (line 5). It uses the Concatenate function to return a string with all of the non-empty values in the output array on a separate line (line 7)

var output = [];
var fields = ["fieldName1", "fieldName2", "fieldName3"];

for (var field of fields) {
  if (!IsEmpty($feature[field])) Push(output,$feature[field]);
}
return Concatenate(output, TextFormatting.NewLine);

 

JamesCarroll7
Occasional Contributor

Thanks for your response, I'll try that expression out this morning!

0 Kudos