You have 2 parcels to Cainiao StationPlease with 10-1-3125 1-5-4453 pickthem up before 1700如何只读取with和pick之间的字符
要读取"with"和"pick"之间的字符,您可以使用字符串的"find"和"substring"方法来实现。以下是一个示例代码:
message = "You have 2 parcels to Cainiao Station. Please with 10-1-3125, 1-5-4453 pick them up before 17:00."
start_index = message.find("with") + len("with")
end_index = message.find("pick")
if start_index != -1 and end_index != -1:
characters_between = message[start_index:end_index].strip()
print(characters_between)
else:
print("Cannot find 'with' and 'pick' in the message.")
输出结果将是:"10-1-3125, 1-5-4453"。这是在"with"和"pick"之间的字符
原文地址: https://www.cveoy.top/t/topic/hYH9 著作权归作者所有。请勿转载和采集!