String into Number

Hello community,

i am having trouble trying to translate a string parameter into a number parameter.
Say i have a string parameter called “DIN” with a value “NUF_Shops”. I would like dynamo to fill a number parameter called “Nummer DIN” with the number 1. i know i shouldnt be using string.replace once the second parameter is not a string, but i dont know what else to do… Can someone help me to find the solution for this?

Thank you very much!

1 Like

try “01” instead of just 01

i did that already, the problem comes back in element.set.parameter.by.name it also seems to expect a string parameter…

If you need to convert from string to number you can use String.ToNumber node:

StringToNumber

thanks luca! but then again how can i transfer the string parameter into the number parameter without using element.setparameterbyname?

This node is supposed to be the final node of your graph. Try adding String to Number as Luca suggested between String.Replace and Element.SetParameterByName

that worked, thanks guys!

another question related to the same script, i am surely doing something wrong here! I wanted to search for all parameters that contain the string “NUF” (NUF_Shops, NUF_Stairs…) and replace them with the String “01”, then use string to number as recommended by @lucamanzoni. The problem is that the result of String.Contains is a boolean that can’t be used in String.Replace… Could someone help me with that? Thanks!!

Hi,

List.FilterByBoolMask to filter the element you want to replace.

Also, try to think to what you are actually feeding your nodes and what they are requiring. String.Replace obvisouly want to be fed strings, not booleans :wink:

2 Likes

7 posts were split to a new topic: Replace Multiple Search Strings

@bialmeida Your second query was off topic and also we can’t have multiple solutions in one thread. Created new post here :point_right: Replace Multiple Search Strings

1 Like