August 2019
Intermediate to advanced
486 pages
13h 52m
English
The string data type is dynamically sized, just like bytes. However, the string type does have support for UTF-8 encoded characters. But on the other hand, the string type does not have .length and .push member functions available. string types are not iterable and do not have random access available.
The string data type variables are assigned by a default empty string, if not initialized.
The bytes type should be used for any arbitrary length of raw data, and the string type for arbitrary length UTF-8 string data. If your string length is known or you can limit the data in smaller size, then bytes1 to bytes32 are preferred, because they are cheaper in terms of gas consumption.