| | |
Saving text manipulated data
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Solved Threads: 0
Hello.
I have a small question/problem.
I have this text file:
I read it into an array in C#, but in my array I read it in as
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:
If you dont understand my question/problem, please speak up
I have a small question/problem.
I have this text file:
C# Syntax (Toggle Plain Text)
// Test 0 0 0 0 15 15 7 // 0 end 1 1 1 30 25 25 240 240 -1 5 // 1 end
I read it into an array in C#, but in my array I read it in as
C# Syntax (Toggle Plain Text)
0 0 0 15 15 7 // 0 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:
C# Syntax (Toggle Plain Text)
string[] SaveMonsterLines = File.ReadAllLines(XMLfileLocation); SaveMonsterLines[linenumber] = "1 1 30 25 25 240 240 -1 5 // 1"; File.WriteAllLines(@"D:/output.txt", SaveMonsterLines);
If you dont understand my question/problem, please speak up
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Solved Threads: 0
Now I got the saving text working by not removing any data from the text file so my array looks like this:
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
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:
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:
Paint event:
And my checkif
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
C# Syntax (Toggle Plain Text)
// Test 0 0 0 0 15 15 7 // 0 end 1 1 1 30 25 25 240 240 -1 5 // 1 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
C# Syntax (Toggle Plain Text)
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:
C# Syntax (Toggle Plain Text)
1 0 30 25 25 240 240 -1 5 // Red Dragon 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:
C# Syntax (Toggle Plain Text)
// Getting cursor position Point p = mapImage.PointToClient(Cursor.Position); for (int i = 0; i < mapRectangleList.Count; i++) { if (mapRectangleList[i].Contains(p)) { ellipseNum = i; break; } } // If ellipsenum is over a ellipse if (ellipseNum > -1) { MessageBox.Show(Convert.ToString(ellipseNum)); displayLine(ellipseNum); } else { // Else show alert MessageBox.Show("Not currently over any ellipse"); }
Paint event:
C# Syntax (Toggle Plain Text)
// Open the data file (msbr = monsterSetBaseRead) StreamReader msbr = new StreamReader(new FileStream(@XMLmonsterSetBaseLocation, FileMode.Open)); // Reading all data while ((MapMonsterSetBaseData = msbr.ReadLine()) != null) { // Splitting data into TxtPiecesMap[] String[] TxtPiecesMap = MapMonsterSetBaseData.Split('\t'); // Checking if data is a correct monster checkIf(MapMonsterSetBaseData); // If it is then continue if (checkIfStatus == true) { // Getting the x and y cord MapXCord = Convert.ToInt16(TxtPiecesMap[3]) * 2; MapYCord = Convert.ToInt16(TxtPiecesMap[4]) * 2; // Creating grapic Graphics g = e.Graphics; // Creating rectangle with cords from coordinates Rectangle r = new Rectangle(MapXCord, MapYCord, 6, 6); // Drawing ellipse on map g.DrawEllipse(Pens.Gold, r); // Adding data for ToolTips and Rectangles lists mapRectangleList.Add(r); }
And my checkif
C# Syntax (Toggle Plain Text)
private void checkIf(string data) { // If monster string is correct if (data != "" && data.Length != 3 && data != "end" && data.Substring(0, 1) != "/" && data.Length != 1) { // Passes checkIfStatus = true; } else { // Failed checkIfStatus = false; } }
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
![]() |
Other Threads in the C# Forum
- Previous Thread: Regarding Sending Mail from C#.net
- Next Thread: How to add DateTimePicker to ToolStrip ?
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast c# check checkbox client clock combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation excel file form format formatting forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math microsystems mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remoting resource restore richtextbox server sleep soap socket sql sqlserver statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml





