跟进将组合框中的信息写入文本文件

时间:2012-12-06 10:07:49

标签: vb.net combobox streamwriter

参考这个帮助主题

Writing information from Combo-box to text file

我无法弄清楚如何在每次参赛后添加空格

例如

约翰 玛丽 乔

而不是

John_ 玛丽_ 乔_

如何填写条目

有问题的代码

Dim sb as new StringBuilder()

For Each item As Object In cmbworld.Items
    'Dim test As String
    'test = item
    sb.AppendFormat("{0} {1}", item, Environment.NewLine)
Next

Dim FILE_NAME As String = "D:\Documents\test.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(sb.ToString()) 'Use the stringbuilder here
objWriter.WriteLine()
objWriter.Close()
    MsgBox("Text written to file")
Else
    MsgBox("File Does Not Exist")
End If

1 个答案:

答案 0 :(得分:1)

删除此处的空格:

sb.AppendFormat("{0} {1}", item, Environment.NewLine)

所以你有:

sb.AppendFormat("{0}{1}", item, Environment.NewLine)