last day (15 days later) » 

12:10
1
A: Split a String to integer array with a delimiter in Solidity?

Achala DissanayakeYou may use a library like stringutils to for that. For your special case, casting the string to bytes and manipulating like the following function will work. contract MyContract{ bytes tempNum ; //temporarily hold the string part until a space is recieved uint[] numbers; functio...

Thanks! Do you know of this library is already deployed on Rinkeby testnet? Can you describe what your code does? Is 0x20 used as a separator? What if a real byte takes this value?
0X20 is the hex value of 32 which is the char value of space , you can change the delimeter by changing that value, for your case since it's spsce I used 0x20
I'll add some comments in the code
is it clear now?
Yes, Thank you! It is so nice, just what I needed.
Your code has some minor errors, like the temp.push().
Thanks for pointing out, and another one, It may need to push the last tempNum after coming out of the loop, otherwise last number will be missing, I'll edit it
Do you think it would be more efficient to have the oracle service return the numbers as raw bytes? Then parseInt() would not be required (It is expensive, right?). Would the code look similar then?
Say, each number is 4 bytes(32 bit)
12:10
What I feel is then you may skip the string to bytes cast step, but if your need is to get an array of numbers you will still need to convert them to uint? You can use your own function to convert string to uint, I'll post one here as well, but you will have to compare it with the cost to use parseInt
Sure, please post it. :-)
Check it, you can convert bytes to int straight away
Last question, can you convert a “bytes” to “uint”? If so, how? By “bytes” I mean an array.
yes, I did post that one, not the string to uint :) didn't see my comment above? ;)
I changed the question title too, accept it if its more relavant
Yes, but you assume the bytes are hex repr. of ASCII numbers? Say bytes contains 0x00 0x00 0x00 0xFF, then I want to convert this sequence to 255.
Can’t I just cast bytes to uint?
12:10
I'm not very sure. I think you may search for hex to decimal conversion using solidity.
edited the function to be more generalized to use any delimiter
Hi again, do you have any idea why your method isn't working from my code: pastebin.com/Lns49hLu ?
I checked it in remix ide and it worked as expected, I'll check the code you posted when I get a time
Thank you very much.
Hi again, it works now - it was due to an exceed gas limit exception it didn't work. Oraclize set a default gas limit of 200.000, but your function cost a little more to run ;)
ahh cool, may be it needs optimizations. If you go thru the libraries, you my be able to find an optimized code
Having looked at the stringutils library, I don't think its "split" functions seems more efficient than yours? They return one token at a time.
To use stringutils, I must first deploy it onto the blockchain right? Its basic usage says using strings for *;. So, I don't inherit from stringutils?
12:10
You may test the function found in library using the remix ide and find the gas cost, so you can know accurately which one is cheap. refer this question regarding libraries

last day (15 days later) »