Lesson contents

Working with strings

Join two pieces of text in the order you want them to appear.

Simple example

Join two letters.

StartA + B
ResultAB
main.rs
fn main() {
    let line = format!("{}{}", "A", "B");
    println!("{}", line);
}
Output
AB
Advertisements

Everyday examples

A shelf label starts with the aisle letter and ends with the shelf number. Make the label for shelf 12 in aisle C.

StartC + 12
ResultC12
main.rs
fn main() {
    let line = format!("{}{}", "C", "12");
    println!("{}", line);
}
Output
C12
Run the example
Terminal
rustc main.rs
./main
Official documentation