22219/string-conversion-to-array-in-solidity
In Solidity, is there a way I can convert my string text to an array using a separator to identify the composite parts within the string
Example
mystring = "This-Is-A-Problem";
to
myArray = [This,Is,A,Problem]; // using hyphen as separator
For n parts we have n-1 delimiters. The code will be like this:
import "github.com/Arachnid/solidity-stringutils/strings.sol"; contract Contract { using strings for *; // ... function smt() { var s = ""This-Is-A-Problem"".toSlice(); var delim = "-".toSlice(); var parts = new string[](s.count(delim) + 1); for(uint i = 0; i < parts.length; i++) { parts[i] = s.split(delim).toString(); } } }
import "github.com/Arachnid/solidity-stringutils/strings.sol"; contract Contract { using strings for *; function smt() public pure { strings.slice memory s = "This-Is-A-Problem".toSlice(); strings.slice memory delim = "-".toSlice(); string[] memory parts = new string[](s.count(delim)); for (uint i = 0; i < parts.length; i++) { parts[i] = s.split(delim).toString(); } } }
https://ethfiddle.com/TgY5JxLKvn
There is no built-in method/function for this but you can use solidity-stringutils. then
import "github.com/Arachnid/solidity-stringutils/strings.sol"; contract Contract { using strings for *; // ... function smt() { var s = ""This-Is-A-Problem"".toSlice(); var delim = "-".toSlice(); var parts = new string[](s.count(delim)); for(uint i = 0; i < parts.length; i++) { parts[i] = s.split(delim).toString(); } } }
Look at the following code : function uintToString(uint ...READ MORE
You are missing the padding in the ...READ MORE
Try this code, may be it works for ...READ MORE
At first, make sure that the string ...READ MORE
This was a bug. They've fixed it. ...READ MORE
Just remove the json_encode call, and it should work: $resp ...READ MORE
Summary: Both should provide similar reliability of ...READ MORE
I found a similar code somewhere: contract Holders{ uint ...READ MORE
Integers in Elixir are arbitrary precision integers, ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.