Extract a substring from a string value

Isolate a portion of a string identified by a range of characters.


Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):


Use this solution in your Compute@Edge service:

  1. Rust
// s.chars().skip(a).take(b).collect()
// will take a substring from `s` across the range [a..(b+a))
// If [a..(b+a)) is out of range,
// we will take as much as possible without panicking.
let s = "afoobar";
let substr: String = s.chars().skip(1).take(3).collect();
// resp_body will be "left=foo"
let resp_body = format!("left={}", substr);