[RESOLVED] How to Write Listbox Items to One Line?
http://img848.imageshack.us/img848/9179/2j2j8d8.png
I need to know how to write the items in the right listbox to a .txt file using StreamWriter. I need the output line to resemble:
Code:
"set sv_mapRotation map mp_abandon map mp_afghan map mp_boneyard map mp_brecourt map mp_checkpoint map mp_complex map mp_crash"
The order should be just like it is in the right listbox.
This is the code that I have set up to begin this:
Code:
myWriter.WriteLine("set sv_mapRotation" + " " + """" + """")
If you need more information please let me know. I'd be more than willing to provide it. Sorry I can't be more detailed at the moment as I'm in a rush.
Any and all help is appreciated.
Re: How to Write Listbox Items to One Line?
try this:
vb Code:
myWriter.WriteLine("set sv_mapRotation " & String.Join(" ", ListBox1.Items.Cast(Of String).ToArray))
Re: How to Write Listbox Items to One Line?
Assuming that the listbox on the right hand side is listbox2 you can do something like this:
vb Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ListboxCount As Integer
ListboxCount = ListBox2.Items.Count
Dim myString As String = "set sv_mapRotation "
Dim myMaps As String = Nothing
For i = 1 To ListboxCount
myMaps = myMaps + " " + ListBox2.Items.IndexOf(i).ToString
Next
myString = myString + myMaps
MsgBox(myString)
End Sub
The Line MsgBox(myString) just gives you a way to verify the string when you are finished.
Re: How to Write Listbox Items to One Line?
@ .paul.
Thank you sooo much. That worked perfectly.
@ mbutler755
Thanks for the input, but .paul.'s code was much more condensed and more suitable for my project.
Thanks to both of you for the quick replies!