Q:

Opening a file and using the string within

When I open a file (I made myself) I need to use somethings out of the string of text that comes trough. I want to use some parts of the text as coordinates to draw a graph with.
    private void openToolStripMenuItem_Click(object sender, EventArgs e)
    {
        char XgetalEen;
        char XgetalTwee;
        char YgetalEen;
        char Ygetaltwee;
        string XgetalSamen = "";
        string YgetalSamen = "";
        int coordinaatX;
        int coordinaatY;
        DialogResult lel = MessageBox.Show("Do you want to close this file?", "OPEN", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        if (lel == DialogResult.Yes)
        {
            Open();
            foreach(string s in Gcowde)
            {
                XgetalEen = s[5];
                XgetalTwee = s[6];
                YgetalEen = s[8];
                Ygetaltwee = s[9];
                XgetalSamen += XgetalEen + XgetalTwee;
                YgetalSamen += YgetalEen + Ygetaltwee;
                if(XgetalTwee==' ')
                {
                    XgetalSamen = "";
                    XgetalTwee = '0';
                    XgetalSamen += XgetalTwee + XgetalEen;
                    YgetalEen = s[7];
                    Ygetaltwee = s[8];
                    YgetalSamen = "";
                    YgetalSamen += YgetalEen + Ygetaltwee;
                }
                if(Ygetaltwee==' ')
                {
                    Ygetaltwee = '0';
                    YgetalSamen = "";
                    YgetalSamen += Ygetaltwee + YgetalEen;
                }
                MessageBox.Show(XgetalSamen + "  " + YgetalSamen);
                Int32.TryParse(XgetalSamen, out coordinaatX);
                Int32.TryParse(YgetalSamen, out coordinaatY);
                currentLocation.X += coordinaatX;
                currentLocation.Y += coordinaatY;
                Coord.Add(new Point(currentLocation.X, currentLocation.Y));

            }
            drawerryting();
        }
    }

    public void Open()
    {
        Gcowde.Clear();
        listBox1.Items.Clear();
        Coord.Clear();
        werkVlak.Clear(Color.Black);
        Coord.Add(new Point(pictureBox1.Width / 2, pictureBox1.Height / 2));
        drawerryting();
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            StreamReader sr = new StreamReader(openFileDialog1.FileName);
            string errything = sr.ReadToEnd();
            string charAdded = "";
            foreach (char s in errything)
            {

                if (s == '\n')
                {
                    Gcowde.Add(charAdded);
                    charAdded = "";
                }
                else
                {
                    charAdded += s;
                }
            }
            foreach (string s in Gcowde)
            {
                listBox1.Items.Add(s);
            }
            sr.Close();
        }

This is the code how I open the file and get the coordinates out of the string. The string is of this kind L1 G2 X50 Y50. i need to get the 2 50s out of the string.
ps.: the variables are in dutch. 
XgetalEen = XnumberOne, XgetalTwee=XnumberTwo, 

same goes for Y. 
XgetalSamen=XnumberTogether, YgetalSamen=YnumberTogether.

A:

This is a simple example how you could parse the file:
// Read your file using File.ReadAllLines
String[] lines = new[] { "L1 G2 X50 Y50", "L1 G2 X50 Y50" };
foreach (var line in lines)
{
     String[] values = line.Split(' ');
     string x = values.Where(s => s.StartsWith("X")).First().Replace("X", String.Empty);
     int xCoordinate = Convert.ToInt32(x);            
}

Don't forget to add all necessary checks and reading of other variables.

