Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Saving text manipulated data

Saving text manipulated data

Scheduled Pinned Locked Moved C#
questioncsharpdata-structureshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Casper Hansen
    wrote on last edited by
    #1

    Hello. I have a small question/problem. I have this text file: // 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 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: 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 :)

    C C 3 Replies Last reply
    0
    • C Casper Hansen

      Hello. I have a small question/problem. I have this text file: // 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 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: 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 :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you throw away information, then you need to remember what it was, so you can restore it at the end. Or did I miss what you were asking ?

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • C Casper Hansen

        Hello. I have a small question/problem. I have this text file: // 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 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: 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 :)

        C Offline
        C Offline
        Casper Hansen
        wrote on last edited by
        #3

        All right.. I will try to explain again I have the array MonsterDataArray which contains the data from the text file The array looks like this: 0 0 0 15 15 7 // 0 1 1 30 25 25 240 240 -1 5 // 1 And both of the lines above has a line number in the array which is 0 and 1 Now I changed something in my array. Lets say I changed line number 0 I changed it from: 0 0 0 15 15 7 // 0 to: 4 7 2 30 45 9 // bleh Now the line number 0 is updated in the MonsterDataArray, but it is not updated in the text file This is where my problem is.. I dont know how to save the changed line number 0 from my MonsterDataArray to my text file because if I use my current code the line number from my array doesnt match up with my text file since I removed some things I hope this helps

        1 Reply Last reply
        0
        • C Casper Hansen

          Hello. I have a small question/problem. I have this text file: // 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 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: 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 :)

          C Offline
          C Offline
          Casper Hansen
          wrote on last edited by
          #4

          Now I got the saving text working by not removing any data from the text file so my array looks like this: // 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 List mapRectangleList = new List(); 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 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: // 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: // 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) {

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups