On Aug 22, 11:24*am, Prime Mover <eple...@hotmail.comwrote:
Thank you so much. That worked perfectly.
Emil
On 22 ago, 12:48, "MC" <for.address.l...@www.ai.uga.edu.slash.mc>
wrote:
using (TextWriter tw = new StreamWriter("output.txt"))
{
* *...
* * * * *tw.WriteLine("{0:###.###} {1:###.###} {2:###.###}", x[i], y[i],
z[i]);
* *...
} *// output stream is automatically closed here
I believe that's one way to do it.
--
Michael A. Covington, Associate Director
Institute for Artificial Intelligence
The University of Georgia, Athens, GA 30602-7415www.ai.uga.edu/mc
You can use:
using (StreamWriter sw = new StreamWriter("C:\output.txt"))
{
for(int i =0; i < n; i++)
{
//Format and write...
sw.WriteLine(string.Format("{0:###.###} {1:###.###}
{2:###.###}", x[i], y[i], z[i]));
} //end for
} //end using
----------------------
Although, I think the below way would be better, because the above way
has a constantly open connection to the file while your program
formats the strings and then writes the line.
----------------------
StringBuilder str = new StringBuilder();
for(int i = 0; i < n; i++)
{
//Format the string
str.Append(string.Format("{0:###.###} {1:###.###} {2:###.###}", x[i],
y[i], z[i]));
} //end for
//Write to the file...
using (StreamWriter sw = new StreamWriter("C:\output.txt"))
{
sw.WriteLine(str.ToString());
}
str = null;