I have a view function which takes a string as input and split the string into substring and i want to define a string array inside the function depending on the number of substrings that the function parameter contain and perform some logic on it. But I fail to do this. Is there a solution to do this or is it impossible in solidity to define array size during runtime?


function retrieveProducer(string _input) public returns(string) 
    string memory s1 = _input;
    string memory s2;
    string  memory s3;
    bytes memory s1bytes = bytes(_input);
    uint index = 0;
    uint totallength = BCServiceList.length;
    uint paramNumber = 0;
    while(s1bytes.length != 0)
       (s2,s1) = splitString(s1,";");
        paramNumber = paramNumber.add(1);
       s1bytes = bytes(s1);
    string[] memory localStringArray= new string[](paramNumber); 
    //do some logic and return a string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.