Maybe this would help. Is from StreamWriter
class documentation.
string[] str = String.Split(...);
// Write each directory name to a file.
using (StreamWriter sw = new StreamWriter("CDriveDirs.txt"))
{
foreach (DirectoryInfo dir in cDirs)
{
sw.WriteLine(dir.Name);
}
}
The idea is to get the text from your textbox and then split it after \n
char. The result will be an array of strings, each element containing one line.
Later edit:
The problem is that return carriage is missing. If you look with debugger at the code, you will see that your string has only \n
at a new line instead of \r\n
. If you put this line of code in you function, you will get the results you want:
string tbval = richTextBox1.Text;
tbval = tbval.Replace("\n", "\r\n");
There should be other solutions for this issue, looking better than this but this one has quick results.