Something like (untested): out = [] for ch in instring: if ch==backspace: if out: out = out[:-1] else: out.append(ch) outstring = ''.join(out) - Pad.