SAIL expression for finding any of a set of characters within a string variable

Hi all,

I am looking for SAIL functions or logic I can use to find any of multiple characters within a string variable.

I have three variables as follows -

a!localVariables(


local!userInput: "Sample user input",
local!charactersOfInterest: {"+", "$", "£", "€", "%"},
local!isFoundCharacterOfInterest:  -TRUE if any of the characters in local!charactersOfInterest are found in local!userInput, otherwise FALSE.-
.

.

Any ideas how search local!userInput for any of the characters in local!charactersOfInterest and return true if any of the characters are found, otherwise return false?

Thanks

  Discussion posts and replies are publicly visible

Parents
  • +2
    Certified Lead Developer

    Basically for something like this, you can just loop over the set of characters of interest and use a function like "search" to search the original user input string for the current item - that would produce a list of booleans, which you can wrap in an or() statement to return true when any are true.

    a!localVariables(
    
      local!userInput: "Sample user in+put",
      local!charactersOfInterest: {"+", "$", "£", "€", "%"},
      
      local!isFoundCharacterOfInterest: or(
        a!forEach(
          local!charactersOfInterest,
          search(fv!item, local!userInput) > 0
        )
      ),
      
      local!isFoundCharacterOfInterest
    )

Reply
  • +2
    Certified Lead Developer

    Basically for something like this, you can just loop over the set of characters of interest and use a function like "search" to search the original user input string for the current item - that would produce a list of booleans, which you can wrap in an or() statement to return true when any are true.

    a!localVariables(
    
      local!userInput: "Sample user in+put",
      local!charactersOfInterest: {"+", "$", "£", "€", "%"},
      
      local!isFoundCharacterOfInterest: or(
        a!forEach(
          local!charactersOfInterest,
          search(fv!item, local!userInput) > 0
        )
      ),
      
      local!isFoundCharacterOfInterest
    )

Children