Select to view content in your preferred language

Arcade: How to find string/phrase with apostrophe, ie. can't

2833
3
Jump to solution
06-15-2021 07:05 AM
Labels (1)
KellyArmstrong
Frequent Contributor

I am trying to find features that have value in a field that has an apostrophe.  How does one do this?

Here is what I have, but it won't work because of the apostrophe in Can't: 

 

else if ( $feature["media_type"] == 'Can't Find Curb Tie') {
return "Can't Find Curb Tie"
}

0 Kudos
2 Solutions

Accepted Solutions
ReeseFacendini
Esri Regular Contributor

Try changing the single quotes to double quotes around the string you are trying to find

"Can't Find Curb Tie"

View solution in original post

jcarlson
MVP Esteemed Contributor

You can use "\" to escape individual characters, too, though simply swapping double quotes is probably simpler.

'Can\'t Find Curb Tie'
- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
ReeseFacendini
Esri Regular Contributor

Try changing the single quotes to double quotes around the string you are trying to find

"Can't Find Curb Tie"

jcarlson
MVP Esteemed Contributor

You can use "\" to escape individual characters, too, though simply swapping double quotes is probably simpler.

'Can\'t Find Curb Tie'
- Josh Carlson
Kendall County GIS
rachelm
Regular Contributor

I tried to use Arcade's Filter function but it failed to create a proper sql statement with the single apostrophes (working in Hebrew, so this may be an added factor).

So I used the above to create a loop with an if statement to mimic the filter function on my tables.  This queries a lookup table and finds a specific value, to grab the corresponding attributes:

var plantname = $feature["L_PlantHebName"]   //input value

var tbl = FeatureSetByName($datastore,"PlantLookupTable", ['PlantHebName', 'PlantCode'], false)  

var fixed_name = Replace(plantname, "'", "\'")
for (var table_row in tbl){
  if(table_row.PlantHebName == fixed_name ){
    return table_row.PlantCode
  }
}