String
In Solidity data types are classified into two categories: Value type and Reference type.

  • Strings in Solidity is a reference type of data type which stores the location of the data instead of directly storing the data into the variable.
  • They are dynamic arrays that store a set of characters that can consist of numbers, special characters, spaces, and alphabets.
  • Strings in solidity store data in UTF-8 encoding.
  • Like JavaScript, both Double quote(” “) and Single quote(‘ ‘) can be used to represent strings in solidity.
String and Memory
  • It is important to know that you can not just return a string in solidity because it has to go somewhere, a string has to be stored. In order to store it, we want to let solidity know to store our string to memory.
  • memory is much like RAM.
  • memory in Solidity is a temporary place to store data whereas storage holds data between functions.
  • The Solidity Smart Contract can use any amount of memory during execution, but once the execution stops, the memory is completely wiped off for the next execution.
Escape Characters

Character Description
\” Double quote
\’ Single quote
\n Starts a new line
\\ Backslash
\t Tab
\r Carriage return
\b Backspace
\xNN Hex escape
\uNNNN Unicode escape
Bytes to String Conversion
Bytes can be converted to String using string() constructor.

bytes memory bstr = new bytes(10);
string message = string(bstr);
Video : Solidity String
Resource File
Question / Answer

bytes memory bstr = new bytes(10);
string message = string(bstr);