2021-05-31 05:37:11 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
|
|
|
|
contract TestStrings {
|
|
|
|
string string1;
|
|
|
|
|
2021-06-02 05:53:33 +00:00
|
|
|
// String type variable takes the next single slot.
|
|
|
|
// If data is 32 or more bytes, the main slot stores the value length * 2 + 1 and the data is stored in keccak256(slot).
|
|
|
|
// Else the main slot stores the data and value length * 2.
|
|
|
|
// https://docs.soliditylang.org/en/v0.7.4/internals/layout_in_storage.html#bytes-and-string
|
2021-05-31 05:37:11 +00:00
|
|
|
string string2;
|
|
|
|
|
|
|
|
// Set variable string1.
|
|
|
|
function setString1(string memory value) external {
|
|
|
|
string1 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set variable string2.
|
|
|
|
function setString2(string memory value) external {
|
|
|
|
string2 = value;
|
|
|
|
}
|
|
|
|
}
|