Home > Mobile >  I am trying to input a list of 200 X,Y coordinates and then output a list of commands with those coo
I am trying to input a list of 200 X,Y coordinates and then output a list of commands with those coo

Time:11-23

I am trying to making a simple tool Windows form app, that I can paste a list of 200 X,Y coordinates and then I can click a button and the tool will output a text file with a command on each line that will have the X,Y coordinates in it.

the input looks like this:

65737,163129
-21687,-27399
164089,50153
164649,63465
-28663,140057
-28951,110329
149833,-30231

and the output should look something like this:

waypoint:WLM 1:1:78168:~:1560:1:true:0:gui.xaero_default:false:0:false
waypoint:WLM 2:2:919432:~:154200:11:true:0:gui.xaero_default:false:0:false
waypoint:WLM 3:3:791080:~:15624:0:true:0:gui.xaero_default:false:0:false
waypoint:WLM 4:4:79288:~:16968:6:true:0:gui.xaero_default:false:0:false
waypoint:WLM 5:5:79064:~:155702:9:true:0:gui.xaero_default:false:0:false

This is what I have so far, I was able to parse the input into a array but now i have no idea how to combine it and save it as a text file.

private void button2_Click(object sender, EventArgs e)
        {
            var lines = richTextBox1.Text.Split((new char[] { ',' }), StringSplitOptions.RemoveEmptyEntries);
            foreach (var s in lines)
            {



                string[] result = lines.ToArray();
                outputwindow.Text = String.Join("\n", result); // parse string so they are all on new lines ( they are still in the array as one tho)

                var cords = outputwindow.Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); // we split the data again and now the result is cords by them selves
                foreach (var c in cords)
                {
                    string[] cordstoarray = cords.ToArray(); // cordstoarry should now be the proper data set

                    //waypoint:name:initials:x:y:z:color:disabled:type:set:rotate_on_tp:tp_yaw:global

                    

                    decimal startnumb = startingnumberb.Value;

                    
                    // wc[1]   wc[0]   name   wc[0]   inl   wc[0]   cordstoarray[0]   wc[0]   wc[3]   wc[0]   cordstoarray[1]   wc[0]   wc[4]

                    

                    for (int i = 0; i < cordstoarray.Length; i  )
                    {
                        string[] buildwaypoints = new string[13]; 

                        string[] wc = { ":", "waypoint", "~", "1:false:0:gui.xaero_default:false:0:false" };

                        string name = nametextbox.Text; // get the name

                        string inl = initialstextbox.Text; // get the initials


     
                        buildwaypoints[i] = { wc[1] , wc[0] , name , wc[0] , inl , wc[0] , cordstoarray[i] , wc[0] , wc[3] , wc[0] , cordstoarray[i   1] , wc[0] , wc[4]};  // Build wapypoint array
                       
                        File.WriteAllLines("Triwaypt.txt", buildwaypoints);
                        using (StreamReader sr = new StreamReader("Triwaypt.txt"))
                        {
                            string res = sr.ReadToEnd();
                            Console.WriteLine(res);
                        }

                    }
                    

                    




                    

                }
                    
            }
        }

CodePudding user response:

you can use File.WriteAllLines() - but in a slightly different way

first add List<string> outputLines = new List<string>(); to the start of your program (just after var lines = ...), so that you can start saving your generated lines (or you can use File.AppendAllText if you want to save memory)

Then when you generate your buildWayPoints array - just generate a string to add to the list instead. Something like

outputLines.Add($"{wc[1]}{wc[0]}{name}{wc[0]}{inl}{wc[0]}{cordstoarray[i]}{wc[0]}{wc[3]}{wc[0]}{cordstoarray[i 1]}{wc[0]}{wc[4]}");//assuming your code up to this point was correct, also you can replace the {wc[n]} with the literal text if you feel like it

Should work, but I'd definitely reccomend cleaning up the code around that section. Finally after the loop is finished you need to write your new list of lines to file with something like File.WriteAllLines(@"Filepath", outputLines)

Assuming your question revolved around creating the output file, the above should work perfectly, if your question was actually about properly formatting the input you'd need to explain your logic a bit more clearly - but as a stab in the dark

counter  ;//define counter as int counter = 0; earlier
var twoCords = c.Split(',');
var outputLine = $"waypoint:WLM {counter}:{counter}:{c[0]}:~:{c[1]}:{idk about this one sorry}:true:0:gui.xaero_default:false:0:false";

p.s. one immediate bug I need to mention is you did a foreach(var c in cords) but then you reference cords instead of c in your code

  • Related