Menu
Coddy logo textTech

Strings in Memory

Part of the Fundamentals section of Coddy's Solidity journey. Lesson 9 of 53.

A string holds text. Local string variables need a data location, so write string memory for temporary text used during a function call. Put literal text inside quotes. An argument of type string memory can also supply text for the function to use.

The statements in this excerpt run inside the provided main function.

string memory label = "Workshop";
console.log(label);

The variable refers to temporary text and the console prints its contents. memory describes where the data lives during this call; it is not part of the variable name. Both single and double quotes can delimit ordinary string literals, but this journey uses double quotes consistently.

Use string memory for a local text variable inside a function.

challenge icon

Challenge

Easy

Copy the supplied title into a local string named caption, then print it.

The tests pass arguments to main in this order: string memory title. Each test starts with fresh contract state.

Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.

Try it yourself

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
    function main(string memory title) external view {
        // Write your solution here.
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Solidity playground