[Solved] How to extract last word in richtextbox in c#


Here is the sample code

*> char[] arr = new char[50];

      int i = 0;
    private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
     {
    if (e.KeyCode == Keys.Space)            {
        string str = new string(arr); 
        MessageBox.Show(str);
        Array.Clear(arr, 0, arr.Length);
        i = 0;
    }
    else if (e.KeyCode == Keys.Back)
       {
        i--;
        if (i < 0)
        {
            i = 0;
        }
        arr[i] = ' ';


    }

    else
    {
        arr[i] = (char)e.KeyValue;

        i++;
    }
    }*

This is how you will be able to extract the latest word. Now color yourself the word you like.

solved How to extract last word in richtextbox in c#