我试图将列表框中的所有选定项保存到文本文件中,但是当我保存选定项时,它将写入一些空白,然后仅保存选定项。
Else
Using sw As StreamWriter = New StreamWriter(path, True)
For i As Integer = 0 To ListBox2.SelectedItems.Count - 1
sw.WriteLine(Trim(ListBox2.SelectedItems(i)))
Next
End Using
Using sr As StreamReader = New StreamReader(path, True)
Do While sr.Peek >= 0
newArray.Add(Trim(sr.ReadLine))
Loop
End Using
System.IO.File.WriteAllText(path, Trim(""))
newArray.Sort()
For Each line As String In newArray
Using sw As StreamWriter = New StreamWriter(path, True)
sw.WriteLine(Trim(line))
End Using
Next
End If
答案 0 :(得分:0)
Dim tmpstr = ""
Using sr As StreamReader = New StreamReader(path, True)
Do While sr.Peek >= 0
tmpstr = Trim(sr.ReadLine)
If tmpstr.Length > 0 Then 'here is your problem
newArray.Add()
End If
Loop
End Using