|
-
Aug 28th, 2007, 09:14 PM
#1
Thread Starter
Addicted Member
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
-
Aug 28th, 2007, 09:25 PM
#2
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);
}
}
-
Aug 29th, 2007, 02:48 AM
#3
PowerPoster
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.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 29th, 2007, 10:16 AM
#4
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|