Character to number conversions

Hello everyone,

I need to create a function that will search for strings and replace the characters in those strings with dedicated integers.
As an example, I want “0” to always equal 48, “1” to always equal 49 etc. So if the script sees the string “10”, it would read that and populate a separate parameter with the value “4948”.
My question is, is this what dictionaries can be used for? Secondly, how would that work? I have done a small test as you can see, but I cant get the value to populate with what I need, I just receive nulls. Could anyone point me in the right direction? I am presuming the “Key” input is looking for a single index value basically, but how would you combine multiple values as I need to?

Thanks so much!

It’s an unusual goal - but you’d need to split the keys (assuming each is a single digit), get the dictionary values for these single values, then join the values back up

Thanks for your response Andrew, I know the request is a little different but it needs to be done this way.
Any guidance on how to split the key? I would have to separate each character in the string, I don’t know what I would use as a separator in this case?

something like this

2 Likes

I see, thank you for this Andrew!

Would you know how to make the process more flexible? Basically every number from 0-9 will have a dedicated, 2 digit number assigned to it, and everyone letter of the alphabet with have the same…
So what could happen is I could receive the string “DA 78”… which is the value I would like to feed into the “Key” input so that it can go and find those 4 values in the dictionary and produce an 8 digit number using the values. So is there potentially a way to split the string value “10” into a 1 and a 0?

It’s not really replacing, right? You want to check if the original string contains “x” and then make a value for a separate parameter.

Depending on how many character-integer sets you have, can’t you just run a String.Contains Node and concatenate the new value based on how many/which positives you have?

Edit: Sorry, had the page open while replying.

that is what String.Split is doing- take a look at the outputs from this node

1 Like

Thank you so much Andrew!! it works perfectly.
Appreciate your assistance with this!

Hi Bjorn,

Yes it isn’t replacing, but I have got the solution below from Andrew. Thanks for your time and effort!