String.Contains Node | 'Search for' modifications

Hello Dynamo Users,

I’m trying to filter out elements by size, removing everything what is less than 32.
I faced a problem while trying to use the same script in a different project.

For example, if I want to remove DN15 pipe size by string contains, it will remove DN150 as well. I did a work around by adding space after DN15 and it worked in one project, because I had a list like:

25 mm - 25 mm
.
.
.
15 mm - 15 mm

But in this case I have different pipe fittings and the structure of the “size” parameter is something like this:

25-25
.
.
.
15-15

and my work around won’t work.
Maybe someone can drop me any ideas how to make it suitable for not only 1 project individually?


Thanks.

Why the usage of String.Contains? Perhaps you are better of using the “==” node?

I’m trying to get rid of the elements that has size 15 & 25. The problem is that the size parameter of different elements has different structure. See first code block. It might be even more complicated in different projects.

By using String.Contains node I’m able to filter out 15 & 25 values which is okay. But it filters out values like 150 and 250 as well.

I’m not sure if can do something with == in my case. It’s absolutely fine if I do have exact element parameter structure to compare with. But I don’t.

Unless I can try to filter values 150 & 250 back by adding some more nodes after. Is there a more smarter way to filter this out properly?

inputs = IN[0]
checks = IN[1]

output = []
for check in checks:
	for input in inputs:
		if check in input:
			output.append(input)
OUT = output

Capture

1 Like

Sorry, I don’t think we are on the same page. But I agree, that the python script might be an option.

Find the node based version below. This is the result I’m after.

Adding dyn file as well.
String_Contains_Test.dyn (9.7 KB)

Oh I see. I’d use regex.
input_digits[0] = first value of the list … since all your values in a string are always the same, I can use the first of the pair.
(so “15” --> input_digits[0] is 15)
(so “15 mm - 15 mm” --> input_digits is list 15, 15 … so input_digits[0] is 15)

inputs = IN[0]
val = IN[1]

output = []
import re
for input in inputs:	
	input_digits = re.findall(r'\d+', input)
	if int(input_digits[0]) > val:
		output.append(input)
			
OUT = output

Capture

1 Like

I would say that this is a solution. Thanks!

And I’m glad for this brief explanation as well. It’s always good to know what you are doing instead of copy pasting a code.

Cheers! Case is closed.