スペースバーでキープレス イベントをトリガーするリッチ テキスト ボックスがあります。私が実装した最後に書かれた単語のすべての出現回数を見つけるロジックは次のとおりです。
private void textContainer_rtb_KeyPress_1(object sender, KeyPressEventArgs e)
{
//String lastWordToFind;
if (e.KeyChar == ' ')
{
int i = textContainer_rtb.Text.TrimEnd().LastIndexOf(' ');
if (i != -1)
{
String lastWordToFind = textContainer_rtb.Text.Substring(i + 1).TrimEnd();
int count = new Regex(lastWordToFind).Matches(this.textContainer_rtb.Text.Split(' ').ToString()).Count;
MessageBox.Show("Word: " + lastWordToFind + "has come: " + count + "times");
}
}
}
しかし、うまくいきません。誰かがエラーを指摘したり、修正したりできますか?