Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I would like to do the following:
Here is what I have:
ArrayList List = new Arraylist

List[0] = {string[2]}
List[1] = {string[2]}

If you select List[0] you get [0] = "Hello"
                              [1] "guys"

and if you select[1] you get [0] = "how"
                             [1] = "are you?"

How would I extract the data and write a text file to read:

Hello guys. How are you?

Thanks in advance
Updated 19-Feb-11 21:08pm

You could use logic as below.
This is only pseudocode and you may need to typecase objects into strings etc as required (based on your implementation.

foreach(Array objArr in List)
   string strFinal=string.Empty;
   foreach(string strText in objArr)
      strFinal += strText;
   WriteTofile(strFinal); //This adds this text to a text file

Also, logic to write to a file needs to be implemented as required.
Share this answer
shekarchee 20-Feb-11 2:01am    
Thanks for the snippet. For the strFinal there is no space between the values?
Sergey Alexandrovich Kryukov 20-Feb-11 2:14am    
Well, add space to each element if you want, of '\n' or "\r\n", whatever, what's the big difference?
Sergey Alexandrovich Kryukov 20-Feb-11 2:15am    
Abhinav, I voted 5 for this Answer. Please look at OP's previous question and my answers. I don't know what else to say...
Espen Harlinn 20-Feb-11 10:28am    
Nice and easy, my 5
Abhinav S 20-Feb-11 11:29am    
Thank you.
This is wonderful!

I answered your last question Extracting data from an array.............................................................................[^].

I advised not to use ArrayList (but to use generic List) and your arrays of the size of two, because your intended type was semantically sound, so you should have used a structure with two fields, properly named. You accepted my answer! Now, you repeat exact same "data design" only instead of double[2] you now use string[2]. Let me inform you, that your approach makes no sense, and the change in type means answer.

Your Question is different, and you got correct Answer, but no Answer will really help you if you keep repeating your old mistakes again and again. I don't know what to say… Well, read some manual not just to the point where arrays are explained, but overview structures, classes, generics, members, methods, loops, calls, look at good code samples—

Good luck,
Share this answer
Abhinav S 20-Feb-11 2:17am    
I've gone through your answer (a 5).
Hope the OP is able to understand and choose the best option for his code.
Sergey Alexandrovich Kryukov 20-Feb-11 2:20am    
Well, thank you, hopefully...
Espen Harlinn 20-Feb-11 7:39am    
Good effort, my 5
Sergey Alexandrovich Kryukov 20-Feb-11 12:38pm    
Thank you, Epsen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900