Iterate through string to determine if it contains a substring

Hello,

Goal:
I want to iterate through a string to determine if it contains a substring that is part of a pre-defined list.

Behaviour:
When using IndexOf to determine if the substring is of index > -1, the check does not return the expected results.

Steps:

  1. Main input contains a number and a description.
    image

  2. I have a reference list which I want to compare to the main description to determine if contains any of these searchterms.
    image

  3. I count the number of searches and put all terms in a group.

  4. Create an array of the searchterms and check each [i] against the main description (represented by var SelectedColumn) and if found, exit the search.

Note: since this will be a component, there are some configuration steps to set the column the search should be applied to.

Issue: the index always return -1, expecting that either the variable or the array element is not coming through properly. In this case, it should be larger than -1 because the string "Handle Ashtray
" contains “Ashtray”.

Any insights or corrections would be much appreciated :slight_smile:

Workflow attached.
iterate_indexof.knwf (26.8 KB)

1 Like

Hi @ArjenEX,

I would solve your problem with a Rule Engine (Dictionary) node.

Please have a look at this workflow:
iterate_indexof.knwf (19.6 KB)

Cheers
Kathrin

6 Likes

Thanks Kathrin!
Works indeed as intended

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.