Solution for select_substring