Reputation: 1023
I need to split value of array like
let v: Vec<&str> = token.split("Bearer ").collect();
and log the value of the token the value is Bearer eyJGciOiJSU
and I need to get only eyJGciOiJSU
when I print the v[1]
to the log I got error index out of range, any idea?
Upvotes: 0
Views: 361
Reputation: 6651
Hard to assess without a minimal example, but this works on the playground:
fn main() {
let token = "Bearer eyJGciOiJSU";
let v: Vec<_> = token.split("Bearer ").collect();
println!("{}", v[1]); // prints "eyJGciOiJSU"
let id = token.strip_prefix("Bearer ").expect(r#"Token ought to start with "Bearer""#);
println!("{}", id); // prints "eyJGciOiJSU"
}
Upvotes: 4