Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- // Hexadeicmal number
- assert_eq!(format!("0x{:X}", 255), "0xFF");
- // Octal number
- assert_eq!(format!("0o{:o}", 127), "0o177");
- // Decimal with specific precision
- assert_eq!(format!("{:.2}", 3.14159), "3.14");
- // Formatted string for debug purpose
- assert_eq!(format!("{:?}", vec![1, 2, 3]), "[1, 2, 3]");
- // Formatted string with specific position
- assert_eq!(format!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob"),
- "Alice, this is Bob. Bob, this is Alice");
- // Formatted string with specific name
- assert_eq!(format!("{subject} {verb} {object}", object = "the lazy dog",
- verb = "jumps over", subject = "The swift fox"),
- "The swift fox jumps over the lazy dog");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement