Results 1 to 4 of 4

Thread: TextStreamReader

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    155

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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);
        }
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: TextStreamReader

    PHP Code:
    FileStream file = new FileStream(thefilepathFileMode.OpenFileAccess.Read);
                   
    StreamReader sr = new StreamReader(file);
                   
    string s sr.ReadToEnd();
                     
    char[] theSplit = { ',' };
                   
    string[] theFile s.Split(theSplit);
                    
    sr.Close();
                    
    file.Close();

    for (
    int i 0theFile.Lengthi++)
    {
    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.


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    155

    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
  •  



Click Here to Expand Forum to Full Width