str_sub separately implemented so it can be used with arbitrary strings