To remove the first N characters of a string in Rust, you can use string slicing starting from index N.
In this example,
str1
with a value of "Hello World"
.fn main() {
let str1 = String::from("Hello World");
let modified_str = &str1[3..];
println!("Modified string is: {}", modified_str);
}
Modified string is: lo World
In this example,
str2
with a value of "apple"
.fn main() {
let str2 = String::from("apple");
let modified_str = &str2[2..];
println!("Modified string is: {}", modified_str);
}
Modified string is: ple
In this tutorial, we learned How to Remove first N Characters in a String in Rust language with well detailed examples.