如何从字符串中提取特定字符 - Python 示例
{"title":"You have 2 parcels to Cainiao Station.\nPlease with 10-1-3125, 1-5-4453 pick\nthem up before 17:00.如何只读取with和pick之间的字符内容:要读取"with"和"pick"之间的字符,您可以使用字符串的"find"和"substring"方法来实现。以下是一个示例代码:\n\npython\nmessage = \"You have 2 parcels to Cainiao Station. Please with 10-1-3125, 1-5-4453 pick them up before 17:00.\"\n\nstart_index = message.find(\"with\") + len(\"with\")\nend_index = message.find(\"pick\")\n\nif start_index != -1 and end_index != -1:\n characters_between = message[start_index:end_index].strip()\n print(characters_between)\nelse:\n print(\"Cannot find \'with\' and \'pick\' in the message.\")\n\n\n输出结果将是:"10-1-3125, 1-5-4453"。这是在"with"和"pick"之间的字符。"}
原文地址: https://www.cveoy.top/t/topic/pHPD 著作权归作者所有。请勿转载和采集!