且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取在 RichTextBox c# 中输入的最后一个单词

更新时间:2023-11-09 23:43:58

只需使用 Substring() 方法做一个小技巧:

Just do a trivial trick with Substring() method:

//KeyPress event handler for your richTextBox
private void richTextBox_KeyPress(object sender, KeyPressEventArgs e){
   if(e.KeyChar == ' '){
     int i = richTextBox.Text.TrimEnd().LastIndexOf(' ');
     if(i != -1) MessageBox.Show(richTextBox.Text.Substring(i+1).TrimEnd());
   }
}