how to initialize structure variable

Posted by Oswaldlily under C# on 11/22/2011 | Points: 10 | Views : 1693 | Status : [Member] | Replies : 1
id X Y
1 10 12a
2 12.3 34j
3 23.3 89
4 45.5 45
5 12.6 12

This in notepad...
it has 5 rows..
I need to store this id value,X value ,Y value into structure ... in C#
string[] s="here i have line by line information"


struct elements
{
string id;
string X;
string Y;
}
main()
{
elements e=new elements();
e.id=/*what to come here */
e.X=/*what to come here */
e.Y=/*what to come here */

}
that 5 rows values are not fixed..means it can change..
in this case,how i ll get that position of columns and store in structure .
dont use dataset or table...this is purely in notepad...
I need to put structure in loop so all line ll be stored




Responses

Posted by: Wilpeters on: 11/26/2011 [Member] Starter | Points: 25

Up
0
Down
split the strings, so in your case:

foreach(string x in s)

{
string[] splitString = x.Split(' ');//split the string wherever there is a space
e.id = splitString[0];
e.X = splitString[1];
e.Y = splitString[2];
}


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response