Read file names to compare to 'keywords' in a text box
<p>I am trying to read file names in a local directory and compare each 'filename' with each 'word' stored in a string. The goal is to replace any words in the string with the same word, but as a link to open the associated file (within the text box). Similar to hyper links on the web. Here is what i have so far. I'm not sure how to go about seperating the words in the string 's' for example into an array[], indexed for each word.</p>

<p>Here is a sample of what I have so far. There is another Windows Form not included here.</p>

<pre><code>namespace MSU_Flash_Cards
{
    public partial class Form1 : Form
    {
        static string directoryPath = string.Format("C:\\Users\\{0}\\Desktop\\cards\\", SystemInformation.UserName);
        DirectoryInfo di = new DirectoryInfo(directoryPath);
        Random rand = new Random();

        int cardside;
        int filecount;
        int fileindex;
        string[] filename;

        string[] allLines;

        public Form1()
        {
            InitializeComponent();
            cardside = 0;
            btnFlip.Enabled = false;
        }
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (di.Exists == false)
            {
                MessageBox.Show("Error. Directory does not exist. Please select File&gt;New");
                menuStrip1.Focus();
            }
            else if (di.GetFiles("*.*").Length == 0)
            {
                MessageBox.Show("Error. Card does not exist. Please select File&gt;New");
                menuStrip1.Focus();
            }
            else
            {
                // Randomly get the next card
                SetNextCard();
                txtboxLabel.Text = string.Format("{0} :   {1}", allLines[0], allLines[1]);
                txtboxCard.Text = string.Format("{0}", allLines[0]);
                txtFrontBack.Text = string.Format("[ Front ]");

                cardside = 0;
                btnFlip.Enabled = true;
            }
        }
        private void btnFlip_Click(object sender, EventArgs e)
        {
            if (cardside == 0)
            {
                // if the front is showing, switch to the back
                txtboxCard.Text = string.Format("{0}", allLines[2]);
                cardside = 1;
                txtFrontBack.Text = string.Format("[ Back ]");
            }
            else
            {
                // if the back is listed, switch to the front
                txtboxCard.Text = string.Format("{0}", allLines[0]);
                cardside = 0;
                txtFrontBack.Text = string.Format("[ Front ]");
            }
        }
        private void SetNextCard()
        {
            int x = 0;

            // Check the directory for files &amp; count them
            FileInfo[] rgFiles = di.GetFiles("*.*");
            filecount = di.GetFiles().Length;

            // Create a new array based on the filecount
            filename = new String[filecount];

            // Save each file name in the array
            foreach (FileInfo fi in rgFiles)
            {
                filename[x] = fi.FullName;
                x++;
            }

            // Select randomly a file @ index for reading
            fileindex = rand.Next(0, filecount);

            // Read each line of the current filename using a random fileindex and assign to a global array for use later
            allLines = File.ReadAllLines(filename[fileindex]);
        }
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.Show();
        }
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
</code></pre>
