-
TextStreamReader
Hi:
if I have
2,5,6,8
5,7,8,9
11,68,45,78
...
....
...more
in text or notepad format.
using System.IO, what is the best way to deal with it as
It need to split the text one at the time ( 2 then 5 then 6 then 8 etc)?
One more thing: When I included : using System.IO at the top of the Program
it give me an Error. When I look at the Preference I could not locate "IO", Why?
I have to do it at the program typing System.IO.Streamreader....
Why?
Thanks
Simon
-
Re: TextStreamReader
The StreamReader class is declared in the mscorlib.dll assembly, which is referenced by default in every project. There's absolutely no reason that you should not be able to import the namespace so you must be doing something wrong that you haven't told us about.
As for getting your data, the easiest way would be like this:
Code:
foreach (string line in System.IO.File.ReadAllLines("file path here"))
{
foreach (string part in line.Split(','))
{
MessageBox.Show(part);
}
}
-
Re: TextStreamReader
PHP Code:
FileStream file = new FileStream(thefilepath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
char[] theSplit = { ',' };
string[] theFile = s.Split(theSplit);
sr.Close();
file.Close();
for (int i = 0; i < theFile.Length; i++)
{
MessageBox.Show(theFile[i]);
}//end for
That should work, I didn't test it though.
Are you using a legal copy of VS studio? If not, your include of Sytem.IO may be corrupt
But you basicaly just have to put using System.IO; at the top of page and you are set.
-
Re: TextStreamReader
"Are you using a legal copy of VS studio? If not, your include of Sytem.IO may be corrupt"
YES! It is original.
AND I found out why, I'm using small letter s-->"system" instead of "System"
AND C# is case sensitive !
Anyway Let me try the code.
Thanks Guy, I keep on forgetting about the case sensitive in C#.
Thanks:wave: