Implementation of String#sub.