0

Separating List into Objects

Hello,

I have a list of items that are separated by commas:

Objects = "Red, Blue, Green"
 

I would like to convert them to objects, and loop through each object to see if a condition matches. 

 

Ex.

If Objects = "Red" then true

 

Except, instead of a bunch of if/then statements there has to be a better way. Any suggestions?

4 replies

null
    • Fred
    • 1 mth ago
    • Reported - view
     said:
    I would like to convert them to objects,

     If you are manually typing out the string, you can make things easier by just putting the items into an array. Something like:

    let Objects := ["Red", "Blue", "Green"]
    

    If you are using a text field then you will need to convert a string into an array. To do this, you will need the split() command. It will look something like:

    split(fieldname,", ");
    

    Notice there is a space after the comma as it has to match the exact text in your string.

     

     said:
    and loop through each object to see if a condition matches. 

     Can you be more specific about what you want here?

      • SMoore
      • 1 mth ago
      • Reported - view

       Hi Fred, 

       

      I already have an array that is comma separated. I want to write a loop that examines each object in the array, and if the condition matches, return true. 

      Ex. Array= Red, Blue, Green,

      If Array = "Red", then true, if Array="Orange" then false

      • szormpas
      • 1 mth ago
      • Reported - view

        Hi, you could consider using the contain() function instead of loop like below:

      let array := ["Red","Green","Blue"];
      if contains(array, "Blue") then
          true
      else
          false
      end
      

      Just to check, are you looking to create a new array with a "true" or "false" for each entry in the initial array, or do you want to achieve the result shown above?

      • szormpas
      • 1 mth ago
      • Reported - view

        and this is the new array version:

      let array := ["Red", "Green", "Blue"];
      let newArray := for loop in array do
              if loop = "Orange" then "true" else "false" end
          end;
      newArray
      

Content aside

  • 1 mth agoLast active
  • 4Replies
  • 42Views
  • 3 Following