How to remove char from string?? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to remove char from string?? (/thread-30020.html) |
How to remove char from string?? - ridgerunnersjw - Sep-30-2020 Good morning.... I have a string being returned '@S0601\r\n'.....I am trying to remove the @ at the front using .replace and .lstrip but to no avail....Below is my lastest code try with error that I seem to get on both .replace or .lstrip....Can someone tell me what I am doing wrong? print((s.read(int(k)).rstrip()).lstrip('@')) Thanks
RE: How to remove char from string?? - buran - Sep-30-2020 (Sep-30-2020, 01:17 PM)ridgerunnersjw Wrote: I have a string being returned '@S0601\r\n'I guess it's not a str object but bytes-like object, given that you have s.read(int(k)) - we don't know what s is...foo = b'@S0601\r\n' print(foo.rstrip().lstrip(b'@').decode()) print(foo.decode().rstrip().lstrip('@')) RE: How to remove char from string?? - ridgerunnersjw - Sep-30-2020 Thank you....Yes it is byte adding the b in .lstrip(b'@') seemed to solve it |