Adding one occurrence to string.

0
Hai, I want to add only one occurrence of word to string like, If I have list of names in  name attribute. I want to add these names in another string only one time even though name repeats many times.  
asked
1 answers
0

You could use the isMatch function to look in your list of names to see if it already exists before appending if it doesn’t. So if you are wanting to change $names and potentially append $newname to it, try something like this
 

if (isMatch($names, '.*\b($newname)\b.*')) then
  $names
else
  $names + ' ' + $newname


isMatch lets us use a regular expression, so here we look for zero or more characters before a word boundary, then the name you want to see is in your list of names, followed by another word boundary.

https://docs.mendix.com/refguide/string-function-calls/#12-ismatch

Hope this helps. 

answered