How do I work with data files?

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2007
Posts: 1,613
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

How do I work with data files?

 
0
  #1
Mar 3rd, 2007
So here's the deal. I learned to program with python, and C# is my second step up the ladder. I'm currently learning the language by making a Sudoku game (just porting over the code from python..nothing fancy).

So I ran into a dead end just now...I know how to manipulate data files {*.dat) in python, to store objects/arrays/ etc. How is this done in C#? I need a quick way to open a file, and put/get two objects in/from it.


P.S. is shelving available in C# as well, because something like that is what I'm talking about. (It says somewhere in the python docs or something that shelving[what I'm used to using] is domething from C, or C++[memory is foggy])
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: How do I work with data files?

 
0
  #2
Mar 3rd, 2007
are you trying to write objects to a file?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,613
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: How do I work with data files?

 
0
  #3
Mar 3rd, 2007
yes write and read
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: How do I work with data files?

 
0
  #4
Mar 3rd, 2007
Oh right. Erm I never do such things. I just read in a normal text file and that parse that data into my class or structure.

Since I don't do it I won't be offering any advice. Good luck though.

http://www.codeproject.com/csharp/objserial.asp
Last edited by iamthwee; Mar 3rd, 2007 at 7:17 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: How do I work with data files?

 
0
  #5
Mar 4th, 2007
Scru,

I think what you are after is Serialization (known as pickling in python).

Take a look at this website:
http://blog.kowalczyk.info/kb/serial...n-in-c%23.html

-- Jerry
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 173
Reputation: RwCC is an unknown quantity at this point 
Solved Threads: 4
RwCC's Avatar
RwCC RwCC is offline Offline
Junior Poster

Re: How do I work with data files?

 
0
  #6
Mar 6th, 2007
God you are fond of python ain't ya, mentioned all the time lol. Treat C# like a completely different language, don't try to make comparisons as that just leads to trouble:

StreamReader reader = new StreamReader("MyFile.dat");
string strAllFile = reader.ReadToEnd().Replace("\r\n", "\n").Replace("\n\r", "\n");
string[] arrLines = strAllFile.Split(new char[] { '\n' });
textBox1.Text = arrLines[0];
textBox2.Text = arrLines[2];

That is reading line one from the .dat file and putting it into textbox1, and then reading line 3 and putting that in textbox2 using array.

StreamWriter writer = new StreamWriter("MyFile.dat");
writer.WriteLine("Hello");
writer.WriteLine("World");

That is writing hello and world to two lines in a .dat file.
Sir David Healy - Northern Ireland Goal King
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,613
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: How do I work with data files?

 
0
  #7
Mar 6th, 2007
Yes I love python, lol. It's quite easy.

You guys are right though: all I had to do was look at it differently to get comfortable, and I am now. I've actually come to love some of C#s features, like the strong typing (for some reason...maybe I just like declaring variables and stuff...xD), and the intellisense (even though I think that's an IDE feature).

Oh, and that Resource file thing rocks too.

I'll try that dat file thingie and let you know how it goes.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,613
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: How do I work with data files?

 
0
  #8
Mar 8th, 2007
thank you this works
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC