The way to do this is probably to 'rebuild' the input rather than removing the strings? Let's do a simpler case