- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 89字
- 2021-07-02 23:07:17
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:

推薦閱讀
- C++程序設(shè)計教程
- iOS面試一戰(zhàn)到底
- Unity 2020 Mobile Game Development
- C和C++安全編碼(原書第2版)
- Java程序員面試算法寶典
- Mastering macOS Programming
- GameMaker Programming By Example
- UNIX Linux程序設(shè)計教程
- Scala Data Analysis Cookbook
- C語言程序設(shè)計簡明教程:Qt實戰(zhàn)
- 編程可以很簡單
- Swift High Performance
- React and React Native
- Java程序設(shè)計
- 3D Printing Designs:Design an SD Card Holder