Results 1 to 3 of 3

Thread: [RESOLVED] Split texts files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    256

    Resolved [RESOLVED] Split texts files

    Well, i have to translate this vb6 code:

    Code:
    ff = FreeFile
        Open App.Path & "\UpdateArcadePT\ListaUpdate.dat" For Binary As #ff
            URL = Space$(LOF(ff))
            Get #ff, , URL
        
        Close #ff
        
        If URL = "" Then
         Unload Me
         Else
        
        strLines = Split(URL, vbNewLine)
        For i = LBound(strLines) To UBound(strLines)
            
            If Len(strLines(i)) > 0 Then
                
                strParts = Split(strLines(i), ";")
                
                File.Caption = "Downloading " & strParts(1)
    
    ......
    To C#, i have made this so far:

    Code:
    StreamReader objReader = new StreamReader(Environment.CurrentDirectory + @"\update\files.dat");
                string sLine = objReader.ReadToEnd();
                objReader.Close();
    
                string[] pedacos = sLine.Split('\n');
                for (Int32 i = 0; i < pedacos.Count(); i++)
                {
                    string[]  partes = pedacos.ToString().Split(new char[] {';'});
                    MessageBox.Show(partes.ToString());
                }
    The txt files is in the format:
    1;name.rar;http://somesite
    2;name2.rar;http://somesite

    But the messagebox is returnig: System.String[].

    Any help?
    Last edited by lelejau; Jan 2nd, 2010 at 09:03 PM.






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

    Re: Split texts files

    csharp Code:
    1. string path = Path.Combine(Application.StartupPath, @"update\files.dat");
    2.  
    3. foreach (string line in File.ReadAllLines(path))
    4. {
    5.     string[] fields = line.Split(';');
    6.  
    7.     MessageBox.Show(fields[0]);
    8. }
    Note that the file, according to the original code, is in the application's startup folder, NOT the current directory, which may or may not be the same path.
    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    256

    Re: Split texts files

    Thanks for the help, i got it just fixing this line:

    string[] partes = pedacos[i].ToString().Split(new char[] {';'});






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