Hey, my good friend @dan-i, I need some expert advice!
I’m having some trouble using string[] as an input parameter to a public function, I got tips from @rph in the Moralis Discord channel to use https://ethereum.stackexchange.com/a/1623, but I don’t understand how to use this, and I cannot find any good examples on how to use it.
I’ve tried to create a function that takes in a string and divides it by commas. but there is something wrong with my code, and I can’t figure out where the error is.
It gets reverted when trying to set a byte equal to another.
I’m grateful for any response!
Thank you for taking the time to read and get me in the right direction
function createArray(string memory test) public returns(string[] memory){
bytes1 comma = ",";
bytes memory input = bytes(test);
bytes memory temp;
string[] memory array;
uint j = 0;
uint k = 0;
for(uint i = 0; i < input.length; i++){
if(input[i] != comma ){
temp[k] = input[i]; // This is where it get reverted when trying it in Remix
k++;
} else {
array[j] = string(temp);
j++;
k=0;
}
}
return array;
}