Is there a build-in function in solidity allows to specify a letter in a string at given position like a = string b[i], where i indicates the position of that letter?


Strings aren't currently index-accessible.

From the Solidity docs:

Variables of type bytes and string are special arrays. A bytes is similar to byte[], but it is packed tightly in calldata. string is equal to bytes but does not allow length or index access (for now).

So use bytes instead, though note:

If you want to access the byte-representation of a string s, use bytes(s).length / bytes(s)[7] = ‘x’;. Keep in mind that you are accessing the low-level bytes of the utf-8 representation, and not the individual characters!

| improve this answer | |
  • 1
    is there any update on the matter by now? – Senju Aug 4 '19 at 19:12

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.