cairo by example

strings

In Cairo, a string is a collection of characters stored in a felt252. Strings can have a maximum length of 31 characters.

Examples of strings:

use debug::PrintTrait;
fn main() {
    let x = 'Cairo is awesome';
    x.print();
    let c = 'A';
    c.print();
}

To run this example, first copy the code in a new file and then run cairo-run --single-file file_name in your terminal.



Try it out!
  1. Install the toolchain:
    • For macOS and Linux, run our script:
    • curl -sL https://raw.githubusercontent.com/lambdaclass/cairo-by-example/main/build/installer.sh | bash -s 2.2.0
    • For Windows and others, please see the official guide
  2. Run the example:
    1. Copy the example into a strings.cairo file and run with:
    2. %!s(<nil>) strings.cairo

prev (if expression) next (felt252)