Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Error, I don't understand Pin
David Stone10-Oct-05 5:39
sitebuilderDavid Stone10-Oct-05 5:39 
GeneralRe: C# Error, I don't understand Pin
Lilli Alexis10-Oct-05 5:42
Lilli Alexis10-Oct-05 5:42 
GeneralRe: C# Error, I don't understand Pin
David Stone10-Oct-05 5:45
sitebuilderDavid Stone10-Oct-05 5:45 
GeneralRe: C# Error, I don't understand Pin
Lilli Alexis10-Oct-05 5:52
Lilli Alexis10-Oct-05 5:52 
GeneralRe: C# Error, I don't understand Pin
S. Senthil Kumar10-Oct-05 5:58
S. Senthil Kumar10-Oct-05 5:58 
GeneralRe: C# Error, I don't understand Pin
David Stone10-Oct-05 6:02
sitebuilderDavid Stone10-Oct-05 6:02 
QuestionData Mining using C# Pin
alvinjv10-Oct-05 3:06
alvinjv10-Oct-05 3:06 
AnswerRe: Data Mining using C# Pin
XRaheemX10-Oct-05 4:51
XRaheemX10-Oct-05 4:51 
Since the file is plain text you can use a simple text reader to read the file. Lets say you wanted to parse out all of the lines given into some respective parameters. You would first create a class file that can hold of of the attributes: (I'm writing all of this in the browser, not in a C# compiler so there may be some syntax mistakes...)

<code>
public class MyFile
{
   private string artist;
   private string album;
   private string year;
   private string song;

   public MyFile()
   {
   }

   public string Artist
   {  
      get
      {
          return this.artist;
      }
      set
      {
          this.artist = value;
      }
   }

   public string Album
   {  
      get
      {
          return this.album;
      }
      set
      {
          this.album = value;
      }
   }

   public string Year
   {  
      get
      {
          return this.year;
      }
      set
      {
          this.year = value;
      }
   }

   public string Song
   {  
      get
      {
          return this.song;
      }
      set
      {
          this.song = value;
      }
   }
}
</code>


Once you have this class you can read the file using a TextReader:

<code>
   System.IO.TextReader reader = new System.IO.TextReader(Application.StartupPath + "\\myfile.txt");
   try
   {
      MyFile customClass = new MyFile(); //Create an instance of the custom class above

      while(true)
      {
         string line = reader.ReadLine();
         if(line == null) //End of file
         {
             break;
         }
         ParseText(line,ref customClass);
      }
   }
   finally
   {
      if(reader != null)
      {
         reader.Close(); //Don't forget to ALWAYS close the file
      }
   }

   //Now customClass should be populated with all of the values from the file


The ParseText method would look something like this:

<code>
public void ParseText(string text, ref MyFile customClass) //Parse the text and fill the MyFile attr
{
      if(customClass == null)  // Make sure it's been instantiated
      {
          customClass = new MyFile();
      }
      if(text.IndexOf(":") > -1) //Make sure this is a line we should read
      {
          string[] temp = text.Split(':');
          if(temp.Length > 1) //Make sure we have at least two values
          {
              select(temp[0].Trim().ToLower()) //Lets check on the left value with no whitespace and as lowercase
              {
                   case "artist":
                      customClass.Artist = temp[1];
                      break; // In c# you MUST break each case unless you want it to trickle down
                                    
                   case "album":
                      break; // In c# you MUST break each case unless you want it to trickle down
                      customClass.Album = temp[1];

                   case "year":
                      break; // In c# you MUST break each case unless you want it to trickle down
                      customClass.Year = temp[1];

                   case "song":
                      break; // In c# you MUST break each case unless you want it to trickle down
                      customClass.Song = temp[1];
              }
          }
      }

}



I think that should about do it. Like I said, remember I typed this all in the browser window, so there could be some syntax errors. Try this out and let me know how it goes.
GeneralRe: Data Mining using C# Pin
David Stone10-Oct-05 7:48
sitebuilderDavid Stone10-Oct-05 7:48 
GeneralRe: Data Mining using C# Pin
XRaheemX10-Oct-05 8:54
XRaheemX10-Oct-05 8:54 
GeneralRe: Data Mining using C# Pin
David Stone10-Oct-05 10:05
sitebuilderDavid Stone10-Oct-05 10:05 
GeneralRe: Data Mining using C# Pin
XRaheemX10-Oct-05 10:46
XRaheemX10-Oct-05 10:46 
GeneralRe: Data Mining using C# Pin
David Stone10-Oct-05 10:57
sitebuilderDavid Stone10-Oct-05 10:57 
GeneralRe: Data Mining using C# Pin
XRaheemX10-Oct-05 11:39
XRaheemX10-Oct-05 11:39 
QuestionRe: Data Mining using C# Pin
alvinjv10-Oct-05 23:06
alvinjv10-Oct-05 23:06 
AnswerRe: Data Mining using C# Pin
XRaheemX11-Oct-05 3:09
XRaheemX11-Oct-05 3:09 
QuestionDynamic Image Location in Crystal Report XI Pin
dhol10-Oct-05 2:48
dhol10-Oct-05 2:48 
QuestionDrawing line in c# Pin
newtocsharp10-Oct-05 1:20
newtocsharp10-Oct-05 1:20 
AnswerRe: Drawing line in c# Pin
Christian Graus10-Oct-05 2:09
protectorChristian Graus10-Oct-05 2:09 
AnswerRe: Drawing line in c# Pin
AB777110-Oct-05 22:35
AB777110-Oct-05 22:35 
Questiondiplaying data in datagrid without child table Pin
Rizwan Bashir10-Oct-05 0:56
Rizwan Bashir10-Oct-05 0:56 
AnswerRe: diplaying data in datagrid without child table Pin
Gavin Jeffrey10-Oct-05 1:33
Gavin Jeffrey10-Oct-05 1:33 
GeneralRe: diplaying data in datagrid without child table Pin
Rizwan Bashir10-Oct-05 3:04
Rizwan Bashir10-Oct-05 3:04 
GeneralRe: diplaying data in datagrid without child table Pin
Gavin Jeffrey10-Oct-05 3:57
Gavin Jeffrey10-Oct-05 3:57 
Questionplease help using references in c# Pin
arusmemon9-Oct-05 22:20
arusmemon9-Oct-05 22:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.