I have a text file as follows:
NPSER NASER NQSER
10 5 3
JPNM EPNS RNPS
12 10 11
ACBE MNEF QPNS
25 11 78
This is a simplified data from my long data. I want to automatically find the values of NPSER, NASER, NQSER and so forth.
So far my code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace read_file
{
class Program
{
static void Main(string[] args)
{
TextReader namefile = new StreamReader(@"E:\Code in C Sharp\read-file\read-file\test.txt");
string line = namefile.ReadLine();
Console.WriteLine(line);
Console.ReadLine();
////Read second line
string line1 = namefile.ReadLine();
Console.WriteLine(line1);
Console.ReadLine();
}
static public string[] Returnval(string line)
{
var Returnval = line.Split('\t');
return Returnval;
}
}
}
I have created a function Returnval which splits the string which are tab separated. I want to modify this function which would automatically take new line as input and then I should be able to use the function like this:
Returnval(NPSER, NASER, NQSER)
I tried to add a new line to Returnval function which is as follows:
string line = namefile.Readline();
I got an error saying namefile is not in context.
Any suggestions are highly appreciated.
Regards, Jdbaba
No comments:
Post a Comment