Hello,
I am new with C# but have experienced in other similar languages such as Java. What I am trying to do is search a long .l5k file for any time a line begins with "f_". Once I find this line, I want to grab the whole "f_" phrase i.e. "f_someRandomTextFollows". I know how to find the line that begins with "f_".
How do I grab the whole "f_" word by just knowing the index and not knowing the length?
Thanks for any comments.
This snippet should work:
-
StreamReader SReader = new StreamReader(filelocation);
-
List<string> values = new List<string>();
-
while (!SReader.EndOfStream)
-
{
-
string currentLine = SReader.ReadLine();
-
if (currentLine.StartsWith("f_"))
-
values.Add(currentLine);
-
}
-
SReader.Close();
-
Where 'filelocation' is a string that is where the file is located.
What it does is goes through the stream, and reads each line and stores it in a temp variable 'currentLine'. It then checks that line to see if it starts with "f_". If it does, its added to the 'values' list. You now have every line that starts with "f_" in that list.