How to replace content in "{}"?

let mut str1 = String::from("hello {world}");
let str2 = "rust";

how to replace content in “{}” with str2?

let str2 = "rust";
let str1: String = format!("hello {}", str2);

I might be misinterpreting your question—if you want to do more general find-and-replace of substrings, use str::replace (or one of the related functions) or the regex crate.

I think I need to use regex crate.Thanks a lot.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.