You know, it's so rare for me to encounter a condition where a while-loop is warranted that I didn't even think to use it. Suppose that's a testament to my infantile coding abilities, lol. Thanks Joshua!
So little bit of a complication. I keep ending up in an infinite loop using the while-loop, but I'm not sure why.Here's the code I'm using:
itemName = "Starbucks 1234_"
while str(itemName[-1:]).isdigit() or str(itemName[-1:]) == "_" or str(itemName[-1:]) == " ":
itemDisplayName = itemName[:-1]
I just want to populate the result in 'itemDisplayName' and not neccesarily alter 'itemName' itself.If I use:
itemName = "Starbucks 1234_"
while str(itemName[-1:]).isdigit() or str(itemName[-1:]) == "_" or str(itemName[-1:]) == " ":
itemName = itemName[:-1]
Then everything goes smoothly. But it's when I try to populate the result in a different variable that it seems to run away into the abyss. Thoughts anyone??UPDATE:What I ended up doing in order to solve the above but continue using the while-loop but avoid the infinite loop was to just prepopulate 'itemDisplayName' with the contents of 'itemName' and THEN run the while-loop against the 'itemDisplayName' giving me the result in the variable I wanted.
itemName = "Starbucks 1234_"
itemDisplayName = itemName
while str(itemDisplayName[-1:]).isdigit() or str(itemDisplayName[-1:]) == "_" or str(itemDisplayName[-1:]) == " ":
itemDisplayName = itemDisplayName[:-1]