What is the equivalent to Javascript's .`split() `for Solidity

Hey folks,

Context:
I am working on a passion project to create a practical onboarding manual for web3 developers. It's under heavy editing and a work in progress.

Currently, I am working on the Strings section. I'd figure as the cost of interacting with smart contracts drops due to layer-2s, some amount of string manipulation might be useful under the right context.

Questions:

  1. What is the best practice for splitting a string in Solidity? Strings have few, if any, methods attached to them.
  2. Is there a secure way to have something equivalent to .split() in JavaScript?
  3. Should any string manipulation just be handled client side and the updates pushed to the contract?
  4. Are there any circumstances where on-chain string manipulation might be useful?

Feedback:
Additionally, if anyone has any feedback on any other part of the website, that would be awesome.

Thanks,
CryptoHamilton

Answers:

  1. The best practice is to avoid doing that on-chain.
  2. Of course, there shouldn't be anything unsecured about implementing split in Solidity.
  3. Depending on your product definition of course, but generally speaking, that would be the recommended approach (same goes for anything else that you can do off-chain without violating your product requirements and security)
  4. Most likely (and it's probably impossible to prove the opposite anyway).
1 Like

Thanks for the answers @barakman!

1 Like