0
我有一個程序,我正在創建,當我去刪除空行這是我如何去做。如何從文本文件中刪除空白行? vb.net?
For Each i As ListViewItem In lvSongs.SelectedItems
lvSongs.Items.Remove(i)
CurrentSong = i.SubItems(4).Text 'This is the Songs Path
files = File.ReadAllText("songs.txt") 'The songs path's are in the txt
'I am using this as a list of lines i want to keep in
'the txt file.
Dim linesToKeep As New List(Of String)
For Each line As String In files 'Goes through lines
If Not line.Contains(CurrentSong) Then 'checks to see if line is Current song
linesToKeep.Add(line) 'Adds line if its not CurrentSong to the list
End If
Next
File.WriteAllLines("songs.txt", linesToKeep.ToArray())
但是當我去檢查的txt文件,我得到這個:
實例(但橫寫,每個字母作爲一個新行)
在文本文件我的朋友說:因爲我把行設置爲字符串而不是字符串()。
感謝您的幫助! 詢問更多的信息,如果我很困惑你...
哇,非常感謝。另外,謝謝你解釋得非常好。我一直在做vb.net一段時間現在信不信由你。畢竟這一次我無法弄清楚String和String()之間的區別是什麼。 – ShaneRibz