1

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
  • Well then cast it from calldata to memory. – goodvibration Sep 26 at 6:09
  • I am trying, but slicing is only available for calldata – Felix_Maduakor Sep 26 at 6:20
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]);
  }
| improve this answer | |

Your Answer

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

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