2017-02-10 73 views
0

我有這樣的數據:蟒蛇刪除與特定的端線特定開始行文本文件

test="1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm Please book a daily bridge line, below are the details: Start Date: 06-July-2016 End Date: 05-Aug-2016 Time: 3 pm to 6 pm (3-hr duration) Number of participants: 25 on every friday We require the bridge line daily during this slot. Regards, Smriti Varma." 

test1="Hi Team, Please arrange Audio Bridge call thru Nortel & Landline only for tomorrow Dated 16-Jun-2016 between 12.30 PM to 1.30 PM (IST), Number of Paticipants: 06 1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:" 

我不想在這兩個行:

text="1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:","1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm" 

回答

0

我不知道是什麼你想要的最終結果,但你可以使用str.replace()
因此,像:

test = "1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm Please book a daily bridge line, below are the details: Start Date: 06-July-2016 End Date: 05-Aug-2016 Time: 3 pm to 6 pm (3-hr duration) Number of participants: 25 on every friday We require the bridge line daily during this slot. Regards, Smriti Varma." 

test1 = "Hi Team, Please arrange Audio Bridge call thru Nortel & Landline only for tomorrow Dated 16-Jun-2016 between 12.30 PM to 1.30 PM (IST), Number of Paticipants: 06 1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:" 

text = ["1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:","1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm"] 

test_modified = test.replace(text[0], "") 
test1_modified = test1.replace(text[1], "") 

How to use string.replace() in python 3.x

但是這取決於你的「測試」字符串的複雜性,如果你想一般尋找他們。