Click here to Skip to main content
15,905,136 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a text file data.txt which has this data on it:
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM

My application can read the data from the file:
System.IO.StreamReader = dataFile = new System.IO.StreamReader("C\\data.txt");
string myData = dataFile.ReadToEnd();


And I can split the string:
Array splitString = myData.Split(' ');


Now I want to use the splitted string as values on my program, like this:
Grid viewGrid = new Grid(Coordinates(5,5));
     viewGrid.AddToCollection(new Rov(1,2,'N',"LMLMLMLMM"));
     viewGrid.AddToCollection(new Rov(3,3,'E',"MMRMMRMRRM"));
Posted
Comments
OriginalGriff 4-Oct-13 4:57am    
And?
What help do you need?
What have you tried? Where are you stuck?
Thando Khumalo 4-Oct-13 5:02am    
I need a way to use the splitted string as values on my program
OriginalGriff 4-Oct-13 5:13am    
I guessed that - but remember: we can't see your screen. We can't access your HDD. And we can't read your mind! :laugh:
We have no idea how you are trying to do this, or what problems you are facing - and unless you tell us, we can't know.
So explain! In short, simple words if necessary (some of us can;t read long ones, so it's probably best) exactly where you need help!
MCY 4-Oct-13 6:31am    
use for what?

1 solution

Do like below...
C#
string[] splitString = myData.Split(' ');

if(splitString != null)
{
    if(splitString.Length > 0)
    {
        Grid viewGrid = new Grid(Coordinates(Convert.ToInt32(splitString[0]), Convert.ToInt32(splitString[1]));
        
        viewGrid.AddToCollection(new Rov(Convert.ToInt32(splitString[2]), Convert.ToInt32(splitString[3]), splitString[4], splitString[5]));
        
        viewGrid.AddToCollection(new Rov(Convert.ToInt32(splitString[6]), Convert.ToInt32(splitString[7]), splitString[8], splitString[9]));
    }
}
 
Share this answer
 

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