C# string syntax error
- by Mesa
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;
}
}