Select to view content in your preferred language

Arcade - return concatenated string over multiple lines

1361
6
Jump to solution
12-20-2023 06:42 AM
Labels (1)
James_Shreeve
Regular Contributor

Hi, 

I have a layout which has a map front and centre but also contains textual information from the map series set-up. In this example I have a PDF exported for each site with a unique address - part of the layout is to show the text, my issue is coming from trying to show the address over multiple lines rather than one long comma separated sting (which it is on the feature). 

Example - 

Address on feature = "The House, Long Road, Sunny Place, The World"

How i'd like to show it on the layout =

"The House, 

Long Road, 

Sunny Place, 

The World"

I've looked at a couple of community posts and have the below Arcade code which has been fine for a bit of testing but when I have an address which doesn't get split into 4 arrays it doesn't show anything. I'm not massively fluent in Arcade, I think I need some form of IF statement but I don't really know where to start or if there is a better way to do it at all? Any help would be amazing 🙂

Arcade code...(image also attached)

var address = $feature.Owner_Addr
var SAddress = Split(address, ",")

Concatenate( ' ',SAddress[0], ',',TextFormatting.NewLine,SAddress[1], ',',TextFormatting.NewLine,SAddress[2], ',',TextFormatting.NewLine,SAddress[3])

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

The Concatenate function really shines when you use an array. This code:

var lines = ['The House', 'Long Road', 'Sunny Place', 'The World']

return Concatenate(lines, '\n')

 Would return:

The House
Long Road
Sunny Place
The World

Since the output of Split is an array, your expression could be very straightforward:

return Concatenate(
  Split($feature.Owner_Addr, ','),
  '\n'
)

That would give you one line per item in the address field no matter how many commas there are.

Note: using '\n' for newline doesn't work in every context, so if this doesn't work, you can try '<br>' or TextFormatting.NewLine.

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
CodyPatterson
Frequent Contributor

Hey James,

If possible, could you give this a shot, it's kinda rough I apologize, I'm not in an area that I can test it, but I've had luck using the + symbol instead of concatenate before:

var address = $feature.Owner_Addr
var SAddress = Split(address, ",")

SAddress[0] + ',' + TextFormatting.NewLine +
SAddress[1] + ',' + TextFormatting.NewLine +
SAddress[2] + ',' + TextFormatting.NewLine +
SAddress[3]

James_Shreeve
Regular Contributor

Thank you for your quick response. It's massively appreciated. 

I have tried the above and I still get the same issue that when I don't have an "SAddress[3]" array it's not returning any of the address though.

0 Kudos
CodyPatterson
Frequent Contributor

Hey James,

Sorry to hear that, I'm assuming the program relies on SAddress[3] in some way, maybe a conditional blocking or some similar fashion.

Jcarlson's answer seems very reliable though, definitely something you should check out!

0 Kudos
James_Shreeve
Regular Contributor

Hi, 

No worries at all. Yeah it must do, don't quite know enough about the finer details to know why or if it does though. 

Just read through and tested @jcarlson's answer and it's just what was needed. Thank you again for your response though, i'll make a note of the "+" rather than concatenate function too for possible future uses. 

jcarlson
MVP Esteemed Contributor

The Concatenate function really shines when you use an array. This code:

var lines = ['The House', 'Long Road', 'Sunny Place', 'The World']

return Concatenate(lines, '\n')

 Would return:

The House
Long Road
Sunny Place
The World

Since the output of Split is an array, your expression could be very straightforward:

return Concatenate(
  Split($feature.Owner_Addr, ','),
  '\n'
)

That would give you one line per item in the address field no matter how many commas there are.

Note: using '\n' for newline doesn't work in every context, so if this doesn't work, you can try '<br>' or TextFormatting.NewLine.

- Josh Carlson
Kendall County GIS
James_Shreeve
Regular Contributor

Hi Josh, 

Thank you for helping out and replying to this post so quickly. 

This is brilliant, thank you! I knew there'd be a more efficient way to do it - the fact that this takes into account any number of Splits makes a big difference too as we're not in control of the address data so there could be a variety of number of commas appearing. Really appreciate the full explanation too - picking up more and more Arcade knowledge as I go. 

Thanks again, 

James Shreeve