如何在C#中提取RichTextBox中的最后一个单词 [英] How to extract last word in richtextbox in c#
问题描述
我正在使用Windows窗体.在我的项目中,我需要为富文本框的最后一个单词上色.当有人在应用程序的给定文本框上书写时,我需要将刚写在richtextbox上的最后一个单词涂成红色或其他颜色.
I am working with windows form. In my project i need to color the last word of rich text box. When someone write on the given text box of the application i need the last word that is just written on the richtextbox to be colored red or whatever.
我找到了一种从以下链接中提取最后一个单词的方法
I found a way to extract the last word from the following link
但是,如果可能的话,我需要更多方便的代码来提取最后一个单词.请帮忙.
But i need more handy code to extract the last word if its possible. Please help.
推荐答案
以下是示例代码
*> char [] arr =新的char [50];
*> 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.
这篇关于如何在C#中提取RichTextBox中的最后一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!