Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello Guys,
I have a file named test.txt
that has arrays with sub arrasy like this

{{first}, {last}, {age}}
{{first1}, {last1}, {age1}}

I am trying to read that from a file into array or list in my program.
any sample code or how to do it??
thanks alot for your help
Posted
Updated 27-Apr-12 6:26am
v3
Comments
fjdiewornncalwe 27-Apr-12 12:27pm    
Perhaps you should make an attempt to do your homework yourself. When that doesn't succeed, ask a specific code related question that addresses your area of difficulty. We are not going to do your assignment for you.
EricThe 27-Apr-12 12:29pm    
perhaps you should keep quite if you cant help
VJ Reddy 27-Apr-12 13:21pm    
Marcus Kramer's comment was constructive keeping in view the purpose of home work. He said in the comment to ask code related question, which indicates that people will be interested to help if you have tried something. Your comment shows that you have not taken the suggestion in right perspective.
fjdiewornncalwe 27-Apr-12 12:49pm    
Reason for my vote of 1
For a lousy attitude.
VJ Reddy 27-Apr-12 13:26pm    
Agreed.
The OP has not taken your comment in the right perspective. Please see my comment to OP's comment.

1 solution

The following steps can be used to read the data from the text file into List<string>s

  1. Read the entire content of the text file using File.ReadAllText method explained here http://msdn.microsoft.com/en-us/library/ms143368.aspx[^] into a string
  2. Split this string into an array of main array strings using Regex.Split method with the pattern @"}\s*{"
  3. Write a method which takes a string as parameter and returns a List<string>
  4. Inside the method use Regex.Matches method with the pattern @"{([^{}]*)}", which captures the elements within { } as group elements
  5. Create a List<string>, add each match.Groups[1].Value to this list and return this constructed List
  6. Pass each string obtained in step 2 to this method to obtain each inner list
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 27-Apr-12 22:54pm    
Makes sense, a 5.
--SA
VJ Reddy 27-Apr-12 23:17pm    
Thank you, SA

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