Saving text manipulated data

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 7
Reputation: Dumpen1337 is an unknown quantity at this point 
Solved Threads: 0
Dumpen1337 Dumpen1337 is offline Offline
Newbie Poster

Saving text manipulated data

 
0
  #1
May 3rd, 2008
Hello.

I have a small question/problem.

I have this text file:
  1. // Test
  2. 0
  3. 0 0 0 15 15 7 // 0
  4. end
  5.  
  6. 1
  7. 1 1 30 25 25 240 240 -1 5 // 1
  8. end


I read it into an array in C#, but in my array I read it in as
  1. 0 0 0 15 15 7 // 0
  2. 1 1 30 25 25 240 240 -1 5 // 1

Since this is a easyer way of manipulating with the data, but now I want to save the data to the text file.
I know the line number of my array, but that does not add up with the orginal file since I stripped som things

So my question is: How do I save the manipulated data so it fits with the orginal data?

My code looks like this:
  1. string[] SaveMonsterLines = File.ReadAllLines(XMLfileLocation);
  2. SaveMonsterLines[linenumber] = "1 1 30 25 25 240 240 -1 5 // 1";
  3. File.WriteAllLines(@"D:/output.txt", SaveMonsterLines);

If you dont understand my question/problem, please speak up
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: Dumpen1337 is an unknown quantity at this point 
Solved Threads: 0
Dumpen1337 Dumpen1337 is offline Offline
Newbie Poster

Re: Saving text manipulated data

 
0
  #2
May 3rd, 2008
Now I got the saving text working by not removing any data from the text file so my array looks like this:
  1. // Test
  2. 0
  3. 0 0 0 15 15 7 // 0
  4. end
  5.  
  6. 1
  7. 1 1 30 25 25 240 240 -1 5 // 1
  8. end

But now I ran into another problem

I have a image where I draw ellipses on with the coordinates from my text file (X: 15 Y: 15 and the 2: X: 25, Y: 25). It triggers on the paint event from the image

I also have a mouse down event on my image

I save all my ellipses in a list called
  1. List<Rectangle> mapRectangleList = new List<Rectangle>();

When I do mouse down I see if the mouse is over a ellipse. If it is it jumps to a specific line in my MonsterDataArray, but the problem is when I save all my ellipses in the list I dont take end, 0, // and the other things from my text with. I only take:
  1. 1 0 30 25 25 240 240 -1 5 // Red Dragon
  2. 2 0 30 35 35 185 132 -1 10 // Golden Titan

So when I jump to specific line in my array the line doesnt match up

Yeah im kinda lost here..

Here is the mouse down part:
  1. // Getting cursor position
  2. Point p = mapImage.PointToClient(Cursor.Position);
  3.  
  4. for (int i = 0; i < mapRectangleList.Count; i++)
  5. {
  6. if (mapRectangleList[i].Contains(p))
  7. {
  8. ellipseNum = i;
  9. break;
  10. }
  11. }
  12. // If ellipsenum is over a ellipse
  13. if (ellipseNum > -1)
  14. {
  15. MessageBox.Show(Convert.ToString(ellipseNum));
  16. displayLine(ellipseNum);
  17. }
  18. else
  19. {
  20. // Else show alert
  21. MessageBox.Show("Not currently over any ellipse");
  22. }

Paint event:
  1. // Open the data file (msbr = monsterSetBaseRead)
  2. StreamReader msbr = new StreamReader(new FileStream(@XMLmonsterSetBaseLocation, FileMode.Open));
  3.  
  4. // Reading all data
  5. while ((MapMonsterSetBaseData = msbr.ReadLine()) != null)
  6. {
  7. // Splitting data into TxtPiecesMap[]
  8. String[] TxtPiecesMap = MapMonsterSetBaseData.Split('\t');
  9.  
  10. // Checking if data is a correct monster
  11. checkIf(MapMonsterSetBaseData);
  12.  
  13. // If it is then continue
  14. if (checkIfStatus == true)
  15. {
  16. // Getting the x and y cord
  17. MapXCord = Convert.ToInt16(TxtPiecesMap[3]) * 2;
  18. MapYCord = Convert.ToInt16(TxtPiecesMap[4]) * 2;
  19.  
  20. // Creating grapic
  21. Graphics g = e.Graphics;
  22.  
  23. // Creating rectangle with cords from coordinates
  24. Rectangle r = new Rectangle(MapXCord, MapYCord, 6, 6);
  25.  
  26. // Drawing ellipse on map
  27. g.DrawEllipse(Pens.Gold, r);
  28.  
  29. // Adding data for ToolTips and Rectangles lists
  30. mapRectangleList.Add(r);
  31. }

And my checkif
  1. private void checkIf(string data)
  2. {
  3. // If monster string is correct
  4. if (data != "" && data.Length != 3 && data != "end" && data.Substring(0, 1) != "/" && data.Length != 1)
  5. {
  6. // Passes
  7. checkIfStatus = true;
  8. }
  9. else
  10. {
  11. // Failed
  12. checkIfStatus = false;
  13. }
  14. }

Dont know if this makes any sense

There might be an easier soloution, but I dont know it

Its allmost the same problem as before, but in a diffrent context
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC