Extract a substring from a string value

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

VCL

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

Compute@Edge

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);