我在Visual Basic 2010中創建了一個應用程序,該應用程序允許我輕鬆地爲我的XAMPP本地託管網站創建.dev Web地址。刪除Visual Basic 2010中兩個標記之間的txt文件中的文本
到目前爲止,我已經設法添加到必要的文件,但不能刪除。
我需要一種方法來刪除txt文件中兩個標記之間的所有文本。例如:
120.0.0.1 localhost
120.0.0.1 alsolocalhost
##testsite.dev#start#
127.0.0.1 testsite.dev
##testsite.dev#stop#
##indevsite.dev#start#
127.0.0.1 indevsite.dev
##indevsite.dev#stop#
我想刪除所有的## testsite.dev#之間的文本開頭#和###testsite.dev停止#標記,以及移除標記自己。
在我的Visual Basic代碼,這是我到目前爲止有:
Sub removeText(ByVal siteName)
Dim fileName As String = "hosts.txt"
Dim startMark As String = "##" + siteName + "#start#"
Dim stopMark As String = "##" + siteName + "#stop#"
'Code for removing text...
End Sub
所有我現在需要的是能夠去除我想要的文字,不接觸任何其他文字(這包括不搞亂它的格式化)。
你需要刪除這兩個標誌的完整產品線? –
@TimSchmelter我想刪除標記以及它們之間的所有內容。 – Tam
你不能從文本文件中刪除任何東西(儘管你可能會覆蓋它的一部分)。正常的方法是讀取文件,處理內容,然後編寫新文件或使用更改後的內容覆蓋舊文件。 – igrimpe