Arcade: How do you find a subset of text in a string?

197
2
Jump to solution
2 weeks ago
FranklinAlexander
Occasional Contributor III

This should be super simple to do, but it's driving me crazy. There doesn't seem to be any way of finding a subset of text in a string using Arcade. For example, all I need to do is find out if the word 'Lake' is in a feature name like 'Hurricane Lake FMA'. I can't believe I am having such a hard time with this, I could have done this in 5 seconds using javascript! Find won't work because it returns a number, and even if it returns 0 that is no help if the subtext I need to find starts at index 0. If someone could point out the obvious thing I am missing I would be grateful.

 

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
SteveCole
Frequent Contributor

The Find Reference states that if no match is found it returns a value of -1 so that's how you key in on finding your substring

if (Find('380', 'Esri, 380 New York Street', 0) < 0) {
  return 'Value not found';
} else {
  return 'Value found';
}

View solution in original post

0 Kudos
FranklinAlexander
Occasional Contributor III

Yes, I missed that the first time I checked the reference page, but finally saw it in another post and got it working. Thanks!

View solution in original post

2 Replies
SteveCole
Frequent Contributor

The Find Reference states that if no match is found it returns a value of -1 so that's how you key in on finding your substring

if (Find('380', 'Esri, 380 New York Street', 0) < 0) {
  return 'Value not found';
} else {
  return 'Value found';
}
0 Kudos
FranklinAlexander
Occasional Contributor III

Yes, I missed that the first time I checked the reference page, but finally saw it in another post and got it working. Thanks!