i have to read a text file. the content is separated by special word (here it is "GO"). I want to read the content section by section and assign to a string or string builder. take a database script as an example. can anyone help me to come up with a solution.
Regards,
Anushka
sample of the text file:
GO
GO
GO
Anushka ThilakarathnePosted Aug 2, 2010, 12:57 AM
thanks a lot. using ur idea i have developed my own. depending on ur code.
Thanks for the support.
ANushka
srinivasPosted Jul 30, 2010, 8:09 AM
using System;
using System.IO;
public class TextFromFile
{
private const string FILE_NAME = "TextFile1.txt";
public static void Main()
{
if (!File.Exists(FILE_NAME))
{
Console.WriteLine("{0} does not exist.", FILE_NAME);
return;
}
using (StreamReader sr = File.OpenText(FILE_NAME))
{
String input;
while ((input = sr.ReadLine()) != null)
{
string[] str = input.Split(' ');
for (int i = 0; i < str.Length; i++)
{
if (str[i] != "GO")
{
Console.Write(str[i]);
}
}
Console.WriteLine();
}
Console.WriteLine ("The end of the stream has been reached.");
}
Console.ReadLine();
}
}