Search code examples
type-conversionred-lang

Converting strings to other datatypes in Red


What is the recommended way to convert a string to an integer in Red?

One way I found is:

load "123"
== 123

Is load the best way of getting an integer from a string in Red?

Is there any danger in using load in this way specifically if the string is from an unvalidated source?


Solution

  • Currently, that is the only way, as to action has not been implemented yet. It is safe using load, as it does not do any kind of evaluation and the construction syntax support is very basic (covering just none and logic values).

    EDIT: to action is now available from v0.6.2 on, so to-integer "123" can be used too.