Generate Text File
-
I would like to generate the data retrieved from a dictionary in a text file, and I would like your help please, if anyone can help me with ideas or examples. thank you
Please elaborate on your problem. Am I correct in assuming that you have a Dictionary<type, type> and you want to save it to a text file? If so: 1) Open the file 2) Iterate through your dictionary 3) Write each entry to the file 4) Close the file Which part are you having difficulties with?
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
I would like to generate the data retrieved from a dictionary in a text file, and I would like your help please, if anyone can help me with ideas or examples. thank you
-
Please elaborate on your problem. Am I correct in assuming that you have a Dictionary<type, type> and you want to save it to a text file? If so: 1) Open the file 2) Iterate through your dictionary 3) Write each entry to the file 4) Close the file Which part are you having difficulties with?
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
I have a dictionary that contains the problems and solutions and I want to write the data into a text file as a table, I'm stuck in the writing of these data in text file
A simple way to accomplish this is to iterate over the
KeyValuePair
items and write them out to a Stream. You'll need to delimit the items somehow. I'm not saying this is the best way, but it may achieve exactly what you want."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
I have a dictionary that contains the problems and solutions and I want to write the data into a text file as a table, I'm stuck in the writing of these data in text file
tek 2009 wrote:
want to write the data into a text file as a table
Well, a text file doesn't hold tables, it only holds flat data, so you will have to decide how to store it so that you can retrieve it later. To save it as flat text is simple:
Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("Hello", "There"); dict.Add("Hello again", "There you"); dict.Add("Hello again again", "There you are"); using (TextWriter tw = File.CreateText(@"C:\\\\temp.txt")) { foreach (KeyValuePair<string, string> kvp in dict) { tw.WriteLine(kvp.Key + ":" + kvp.Value); } tw.Close(); }
Anything more complex will need you to think about data storage in a bit more detail!
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
A simple way to accomplish this is to iterate over the
KeyValuePair
items and write them out to a Stream. You'll need to delimit the items somehow. I'm not saying this is the best way, but it may achieve exactly what you want."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
tek 2009 wrote:
want to write the data into a text file as a table
Well, a text file doesn't hold tables, it only holds flat data, so you will have to decide how to store it so that you can retrieve it later. To save it as flat text is simple:
Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("Hello", "There"); dict.Add("Hello again", "There you"); dict.Add("Hello again again", "There you are"); using (TextWriter tw = File.CreateText(@"C:\\\\temp.txt")) { foreach (KeyValuePair<string, string> kvp in dict) { tw.WriteLine(kvp.Key + ":" + kvp.Value); } tw.Close(); }
Anything more complex will need you to think about data storage in a bit more detail!
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
You're welcome.
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.