Download

How can I change a number in string to number in integer

Hello everyone! :smiley:

I have a question…
I have a string variable that contains “Two”…
And i want to set an integer to the equivalent of the string but in number like this “Two” = “2”…

Does anyone has any idea on how to do this??

For how many numbers?

My first idea is to have an array of strings with zero, one, two ect. that returns the index given an if string=two setup, but that would be tedious if you want it to return 365.

Easiest method is to keep the data as an integer, and the display of it be the string which is only updated. Make a TMAP, with an Int as the Key and String as Value. To do it for all numbers you will need to make some logic that gets the 10’s, hunderth’s place etc. and build the string in the same way, from Map’s.

https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/TMap/index.html#tmap

While the TMap is a good thing, this is the Blueprint part of the Forum and even in 4.14, TMaps can’t be created in Blueprints. They can only be accessed.

So the solution needs to be without them for now (as long as OP can’t use C++).

It’s a good call to leave the Number as an actual integer and only convert it if you need it.

Both ways, INT->String and String->INT need to be done by hand.

For INT->String you can do it like this:

Where ever you have your String INPUT, drag it off and search for “Select”.
That node will have a wild card at the bottom. Plug the INT variable into the wildcard
and then you can add Options to the node (Right clicking the Node and selecting “Add Option”).
It counts from 0 to X (how many options you add). You can enter a string for each number.

Other way round, you can call “Switch on String” on the String and use that node
to set an INT Variable when the String equals ONE, or what ever you type into the
Switch node.

While the TMap is a good thing, this is the Blueprint part of the Forum and even in 4.14, TMaps can’t be created in Blueprints. They can only be accessed.

So the solution needs to be without them for now (as long as OP can’t use C++).

It’s a good call to leave the Number as an actual integer and only convert it if you need it.

Both ways, INT->String and String->INT need to be done by hand.

For INT->String you can do it like this:

Where ever you have your String INPUT, drag it off and search for “Select”.
That node will have a wild card at the bottom. Plug in the INT variable into that
and then you can add Options to the node. It counts from 0 to X (how many options
you add). You can enter a string for each number.

Other way round, you can call “Switch on String” on the String and use that node
to set an INT Variable when the String equals ONE, or what ever you type into the
Switch node.

You can also use the String Array idea, where you just enter the Index of each Array element as it’s written version.

Array[0] = Zero
Array[1] = One

As said in a post before, if you need that for high numbers, it might become a lot of work and at that point, you might need
to actually write a more complex code to build numbers out of existing ones.