CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #1
    Join Date
    Mar 2012
    Posts
    14

    [RESOLVED] Need Help with Parser C#

    Okay, I'm making an application on Visual Studio 2010 that will load a CSV file with Text in it such as:

    black, white
    Cat, dog
    Hot, cold

    and so on. So they're separated by a comma. I want to use the loaded file with a streamreader and store the data in a dictionary. I then want to split the text in the file so that the word before the comma could be assigned to [0] and the word after the comma could be assigned to [1] This means that if the user entered a [0] textword into textbox 1 then after clicking a button textword [1] would show in textbox 2. For example,

    User enters black in Textbox 1 and then after clicking a button white is now shown in Textbox 2.
    User enters Cat in Textbox 1 and then after clicking a button Dog is now shown in Textbox 2.

    Here is the code that I currently have:

    Code:
    //Dictionary Load Button
            private void button1_Click_1(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)   //Allows the user to choose the dictionary to load
                
                {  
                   Dictionary<string, int> d = new Dictionary<string, int>();
                   using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
    
                   {
                      string line;
                      while ((line = sr.ReadLine()) != null)
                      {
                          string[] splitword = line.Split(',');
                         
                                         
                                              
                      }
                                  
                   }
                        
                }
    After string[] splitword = line.Split(','); I don't know how to do the rest. Such as assigning [0] and [1] and then the text box code.


    Any help with this would be fully appreciated as I've went to the end of the earth and back trying to figure this out.
    I've had it looked over by my tutor and so far everthing's correct.
    Last edited by Cimperiali; March 17th, 2012 at 01:52 PM. Reason: Added [code][/code] tags

Tags for this Thread

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

Featured