To get the substring after a specific character in Rust, you can use the `split` method followed by iteration to extract the substring.
In this example,
url
with a value of "https://example.com/page"
.'/'
using the split
method and collect the parts into a vector.fn main() {
let url = "https://example.com/page";
let parts: Vec<&str> = url.split('/').collect();
let substring = parts[1];
println!("Substring after '/': {}", substring);
}
Substring after '/': example.com/page
In this example,
str
with a value of "Hello,World"
.','
using the split
method and collect the parts into a vector.fn main() {
let str = "Hello,World";
let parts: Vec<&str> = str.split(',').collect();
let substring = parts[1];
println!("Substring after ',': {}", substring);
}
Substring after ',': World
In this tutorial, we learned How to get Substring after Specific Character in Rust language with well detailed examples.