I am trying to remove the last 3 characters from a string in python, I donโt know what these characters are, so I canโt use rstrip , I also need to remove any space and convert to the upper case
example:
foo = "Bs12 3ab" foo.replace(" ", "").rstrip(foo[-3:]).upper()
This works and gives me BS12, which I want, however, if the last 4th and 3rd characters are the same, I lose both, for example, if foo = "BS11 1AA" I just get 'BS'
Examples of foo might be:
BS1 1AB bs11ab BS111ab
The string can be 6 or 7 characters and I need to discard the last 3 (no spaces)
Any tips?
python string
Sam Machin Nov 25 '09 at 17:14 2009-11-25 17:14
source share