Using the format! macro

The format! macro works in a way similar to string formatters in other languages:

fn main() { 
    let home_team = "Liverpool"; 
    let result = " beat "; 
    let away_team = "Manchester United"; 
     
    let full_line = format!("{}{}{}", home_team, result, away_team); 
         
    println!("{}", full_line); 
} 

The {} in the format strings mark spots for the following parameters. The spots are filled in order, so full_line will be a concatenation of home_team, result, and away_team.

When the preceding code snippet is compiled and executed, you will see the following:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset