我想選擇位於richtextbox文本的最後一個「{」和「}」之間的文本。 我有下一個代碼,但我有一個「LastIndexOf」函數的錯誤,我不知道如何解決它。有人能給我一些幫助嗎?從C#中的Richtextbox中選擇文本
private void highlightText()
{
mRtbxOperations.SelectionStart = mRtbxOperations.Text.LastIndexOf(@"{", 1, mRtbxOperations.SelectionStart);
mRtbxOperations.SelectionLength = mRtbxOperations.Text.IndexOf(@"}", mRtbxOperations.SelectionStart, mRtbxOperations.Text.Length - 1);
mRtbxOperations.SelectionBackColor = Color.LightBlue;
mRtbxOperations.SelectionFont = new Font(mRtbxOperations.SelectionFont, FontStyle.Underline);
mRtbxOperations.SelectionLength = 0;
}
LastIndexOf錯誤:
The count must be positive and must refer to a location within the string, array or collection. Parameter name: count
可能重複(http://stackoverflow.com/questions/455713/selectively-coloring-text-in-richtextbox) –