Using Oraclize, I request a some external data in the form "1 2 3"
, i.e., space-separated integers (OR any other delimiter).
Indeed, these numbers could be requested one at a time, but this would be EXPENSIVE.
Now, to work with these integers, I need to convert them back to integers and store them inside an array.
I know the parseInt()
function for converting a string to a number, but how to I break up the string into "1"
, "2"
, "3"
, such that I can parse the numbers and store them in an array?
Best Answer
You may use a library like stringutils or solidity-util to for that. For your special case, casting the string to bytes and manipulating like the following function will work.
If you can't use
parseInt
you may use your own function to convert to uint as follow found here,Then instead of
numbers.push(parseInt(string(tempNum)));
you can usenumbers.push(bytesToUint(tempNum));
Or you can look into the libraries code and use only the function you need. Those might be efficient.
Hope this helps!