I have an &str type string from which I want to remove a sub-string. I have an algorithm to calculate the start and end positions of the part to be removed. How can I now remove the sub-string?
To illustrate this clearer, if I were using C++, I would do this:
#include<iostream>
#include<string>
int main(){
std::string foo = "Hello";
int start = 2,stop = 4;
std::cout<<foo;
foo.erase(start, stop - start);
std::cout<<std::endl<<foo<<std::endl;
}
My code in Rust:
fn main(){
let mut foo: &str = "hello";
let start: i32 = 0;
let stop: i32 = 4;
//what goes here?
}
(&foo[..start]).to_string() + &foo[end..]