C# string syntax error

Posted by Mesa on Stack Overflow See other posts from Stack Overflow or by Mesa
Published on 2010-06-06T06:17:28Z Indexed on 2010/06/06 6:22 UTC
Read the original article Hit count: 341

Filed under:

I'm reading in data from a file and trying to write only the word immediately before 'back' in red text. For some reason it is displaying the word and then the word again backwords. Please help. Thank you.

private void Form1_Load(object sender, EventArgs e)
        {
            Regex r = new Regex(" ");
            StreamReader sr = new StreamReader("KeyLogger.txt");
            string[] tokens = r.Split(sr.ReadToEnd());
            int index = 0;
            for(int i = 0; i <= tokens.Length; i++)
            {
                if (tokens[i].Equals("back"))
                {
                    //richTextBox1.Text+="TRUE";
                    richTextBox1.SelectionColor = Color.Red;
                    string myText;
                    if (tokens[i - 1].Equals("back"))
                        myText = "";
                    else
                        myText = tokens[i - 1];
                    richTextBox1.SelectedText = myText;
                    richTextBox1.Text += myText;
                }
                else
                {
                    //richTextBox1.Text += "NOOOO";
                }

                //index++;
                //richTextBox1.Text += index;
            }
        }

© Stack Overflow or respective owner

Related posts about c#