How can I append a formatted string to an existing String?

I see now that String implements Write, so we can use write!: use std::fmt::Write; pub fn main() { let mut a = “hello “.to_string(); write!(a, “{}”, 5).unwrap(); println!(“{}”, a); assert_eq!(“hello 5”, a); } (Playground) It is impossible for this write! call to return an Err, at least as of Rust 1.47, so the unwrap should … Read more

Kotlin – String formatting

Unfortunately, there’s no built-in support for formatting in string templates yet, as a workaround, you can use something like: “pi = ${pi.format(2)}” the .format(n) function you’d need to define yourself as fun Double.format(digits: Int) = “%.${digits}f”.format(this) This will work only in Kotlin/JVM. There’s clearly a piece of functionality here that is missing from Kotlin at … Read more

Format in Kotlin string templates

Unfortunately, there’s no built-in support for formatting in string templates yet, as a workaround, you can use something like: “pi = ${pi.format(2)}” the .format(n) function you’d need to define yourself as fun Double.format(digits: Int) = “%.${digits}f”.format(this) This will work only in Kotlin/JVM. There’s clearly a piece of functionality here that is missing from Kotlin at … Read more