tail_to_clip = "_12May11_mm" x = "My_String_Needs_to_be_truncated_12May11_mm" truncated = x.rsplit("_")[:-len(tail_to_clip)]
# this option removes the 11 right characters (if you know it will always be 11) x = 'My_String_Needs_to_be_truncated_12May11_mm' print x[0:-11] # this option builds the string after putting it into an array split at the "_" and removing the last two elements y = x.split("_") y.pop() y.pop() z = "" i = 1 for word in y: if i == 1: z = z + word else: z = z + "_" + word i = 2 print z
x = "My_String_Needs_to_be_truncated_12May11_mm" truncated = x[:31]
x = "My_String_Needs_to_be_truncated_12May11_mm" truncated = x.rsplit("_")[0]
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.