2

I want to slice a string and save it to a memory or storage variable.

Is this possible?

function test(string calldata _input) external{        
    string memory something = _input[1:3];
}

I am getting the following error:

TypeError: Type string calldata slice is not implicitly convertible to expected type string memory
2
  • Well then cast it from calldata to memory. Sep 26, 2020 at 6:09
  • I am trying, but slicing is only available for calldata Sep 26, 2020 at 6:20

1 Answer 1

0

You can explicitly cast it to a string memory by wrapping it in string():

  function test(string calldata _input) external{        
    string memory something = string(_input[1:3]);
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.