Answer» What my program does and is download a string from and uploaded FILE. I need to ADD a new line to the listbox for every line of string in the downloaded string.
so for example
downloaded string = firstlineofstring secondlineofstring
I need to add listbox1.items.add(downloaded string); //add line 1 of string, add line 2 of string, add any other lines
if I just do listbox1.items.add(download string); it will wrap the text and not PAY attention to the newline thats in the string.
so the listbox will look like:
firstlineofstring secondlineofstring
any help WOULD be great. If I understand what you're trying to do, you'll have to SPLIT the downloaded string first before adding it. Something like:
Code: [Select]listbox1.Items.AddRange(downloadedString.Split('\n'));if AddRange is unavailable (I don't remember if you can use it on listbox item collections), then you can alternatively loop through the lines and add each one:
Code: [Select]foreach (string line in downloadedString.Split('\n')) listbox1.Items.Add(line);
You may also need to tweak the arguments to the String.Split method above (see http://msdn.microsoft.com/en-us/library/y7h14879.aspx)
Quote from: TechnoGeek on March 25, 2013, 05:01:48 PM If I understand what you're trying to do, you'll have to split the downloaded string first before adding it. Something like:
Code: [Select]listbox1.Items.AddRange(downloadedString.Split('\n'));if AddRange is unavailable (I don't remember if you can use it on listbox item collections), then you can alternatively loop through the lines and add each one:
Code: [Select]foreach (string line in downloadedString.Split('\n')) listbox1.Items.Add(line);
You may also need to tweak the arguments to the String.Split method above (see http://msdn.microsoft.com/en-us/library/y7h14879.aspx)
Second one worked, thanks a lot.
|