Removing control characters from a string in python -
i have following code
def removecontrolcharacters(line): = 0 c in line: if (c < chr(32)): line = line[:i - 1] + line[i+1:] += 1 return line
this not work if there more 1 character deleted.
you use str.translate
appropriate map, example this:
>>> mpa = dict.fromkeys(range(32)) >>> 'abc\02de'.translate(mpa) 'abcde'
Comments
Post a Comment