I'm working though some basic solidity tutorials using remix. I'm having trouble with the concept that there is no way to edit a string built into the language. In other programing languages I would have different ways to manipulate a string and arrays of letters but it seems like the only way to do that is by importing some custom github string code or by converting it to a byte array, both of which I don't fully understand.

I understand that there is a cost to store data and a cost to do computations on the eth blockchain.

I want to store info, how can I make sure that the information is limited to 64 characters (to save on storage) and that any checking or manipulation of that 64 characters is done as cheaply as possible (to save on computations).

Are there any patterns for working with strings in solidity that I don't know about?

Is big-O notion used to determine the gas cost? Can it? How can I determine how much gas this simple contract will take?

  • 1
    To know more about gas and how it is computed take a look at this question: ethereum.stackexchange.com/questions/3/…. – Ismael Sep 3 at 19:33
  • 1
    Solidity was never meant to be a general purpose programming language so it lacks a lot of higher level abstraction like a string type. There were a few attempts to replace solidity but so far there wasn't enough interest. The more successful attempt is vyper. I'll complain every time I can, but it works. You'll hate its limitations and odd behavior, but many successful project use it. I've learned to accommodate to its deficiencies. – Ismael Sep 3 at 19:38
  • 1
    Depending on the context sometimes it is possible to replace a string by a bytes32, it only allows 32 bytes, so you don't have to worry if the user will send more data because he cannot do so. – Ismael Sep 3 at 19:39

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.