In Rust, you can create an empty string by initializing a String
variable with the String::new()
method.
In this example,
String
variable named empty_string
and initialize it using the String::new()
method.empty_string
now holds an empty string.fn main() {
let empty_string = String::new();
println!("Empty string created: '{}'", empty_string);
}
Empty string created: ''
In this tutorial, we learned How to Create an Empty String in Rust language with well detailed examples.