String Remove Last Character if not number

Hello,

I thought this is simple but i cant find way, how to remove the LAST character in a list if it’s not a NUMBER?
thanks in advance

Maybe this python script can help you.

Would something as follows be what you was after?

Code:

#Created By Brendan Cassidy

output=

for a in IN[0]:
if a[-1].isdigit():

  output.append(a)

else:
output.append(a[:-1])

OUT=output

Image of code:

1 Like

@lucifer Are you after getting rid of all characters at the end until it becomes a number or just the last character if it isnt a number?

If you want to get rid of just the last digit then my first post will work, if not the below may be a better solution

Code(image):

Code:

#Created By Brendan Cassidy

def digitcheck(input):
templist=
count=0
for a in input:
if a.isdigit():
templist.append(count)
else:
templist.append(0)
count=count+1
return max(templist)+1

output=

for a in IN[0]:
output.append(a[:digitcheck(a)])

OUT=output

1 Like

remove just the last character if it’s a letter :slight_smile: Thanks @Brendan_Cassidy

1 Like

Is there also a solution if the last character is a special character?
In example a _ (underscore)?

NB
I am happy with ANY solution how to remove the last character if it is a _ (underscore).

Hello,
Here is a proposal

Cordially
christian.stan