Good question. I don't see why not but you should be able to quickly test this out.
yes you just cast it to bytes and work with the bytes themselves, then back to string
That'll be hell expensive, there should be a direct way
Shouldnt be gas heavy to type cast to bytes and back to string no?
exactly my thought, it might be pretty expensive operation.
I dont think there are another way
function substring(string str, uint startIndex, uint endIndex) constant returns (string) { bytes memory strBytes = bytes(str); bytes memory result = new bytes(endIndex-startIndex); for(uint i = startIndex; i < endIndex; i++) { result[i-startIndex] = strBytes[i]; } return string(result); }
not super expensive, maybe a few thousand gas. There's no other way to manipulate strings in solidity that I know of
solidity is a big oof for strings, I'll try to estimate the fees.
yeah I just ran a test, was like 5k gas above the base tx cost to return a 3 character substring from a 20 or so character one
take out the inputs and returns, and the cost is more like 1700 gas for that string manpulation
oh really, that sounds average
yeah not too bad, but it was a short-ish string.
does substring also works with uints?
to get part of a uint? You'd just use bitwise operations on it
Обсуждают сегодня