How to remove the first and last character of a string in Rust?
To remove first letter and last letter in String we will need to callsplit_at()
function twice first time to remove the last character and second time to remove the first character.Example of removing the first and last character of a string in Rust
fn main() {
let text = "HI User";
// remove last letter
let mut text = text.split_at(text.len() - 1);
// remove first letter
text = text.0.split_at(1);
println!("{}", text.1);
}
Output
I Use