Remove text between brackets with arcade

321
2
Jump to solution
11-05-2021 10:16 AM
OM
by
New Contributor

Hello, I need to remove all html elements in text fields from popups in ArcGIS Pro/ArcGIS Enterprise.  Text fields could contain multiple instances of <>.

text field - Description

<p><span style="color: rgb(68, 68, 68);">this artwork was commissioned through the City's </span>Hogan Alley Artist Call 2019.&nbsp;<span style="color: rgb(68, 68, 68);">In February 2019, the City invited proposals for a temporary painted mural.&nbsp;</span></p> 

Can't find a way to set this up with Arcade

Thanks,

OM

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

It's not terribly elegant, but you can do this with a few nested loops and some splitting and searching.

var str = your-string-attribute

// Split input string by '>' char
var splits = Split(str, '>', -1, True)

// Empty string for output
var outstr = ''

// Iterate over split string
for (var s in splits){
    var substr = splits[s]
    
    // Find items not beginning w/ '<', i.e., not HTML tags
    if (Left(substr, 1) != '<'){
        
        // Check if string ends w/ HTML tag
        var i = Find('<', substr)
        
        // Trim HTML tag from end if present
        if (i != -1){
            substr = Left(substr, i)
        }
        
        outstr += substr
    }
}

outstr

 

And for the proof:

jcarlson_0-1636145966273.png

You'll notice the "&nbsp;" does not get removed, but we were only looking for HTML tags. These could easily be stripped out with a Replace function, though. Or rather than stripping them out, replacing them with '\n'.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Honored Contributor

It's not terribly elegant, but you can do this with a few nested loops and some splitting and searching.

var str = your-string-attribute

// Split input string by '>' char
var splits = Split(str, '>', -1, True)

// Empty string for output
var outstr = ''

// Iterate over split string
for (var s in splits){
    var substr = splits[s]
    
    // Find items not beginning w/ '<', i.e., not HTML tags
    if (Left(substr, 1) != '<'){
        
        // Check if string ends w/ HTML tag
        var i = Find('<', substr)
        
        // Trim HTML tag from end if present
        if (i != -1){
            substr = Left(substr, i)
        }
        
        outstr += substr
    }
}

outstr

 

And for the proof:

jcarlson_0-1636145966273.png

You'll notice the "&nbsp;" does not get removed, but we were only looking for HTML tags. These could easily be stripped out with a Replace function, though. Or rather than stripping them out, replacing them with '\n'.

- Josh Carlson
Kendall County GIS
OM
by
New Contributor

Can't thank you enough for solving this.  It worked great.

Olga

0 Kudos