skywola
Member
In a find-replace operation, when you are very close to the end of the text file, I have found that if you use:
FrmMain.RTBMain.SelectedText = findInstance.replaceString
it adds the text, but does not re-size the file as a whole if you are replacing a small string with a large string,
and then when you try to save the file you get an error. My solution was to add the replace text to the clipboard,
then paste the text from the clipboard over the smaller text, which does re-size the file. However, I would
be that there is a shorter and easier solution. Below is the code:
FrmMain.RTBMain.SelectedText = findInstance.replaceString
it adds the text, but does not re-size the file as a whole if you are replacing a small string with a large string,
and then when you try to save the file you get an error. My solution was to add the replace text to the clipboard,
then paste the text from the clipboard over the smaller text, which does re-size the file. However, I would
be that there is a shorter and easier solution. Below is the code:
VB.NET:
EOF = FrmMain.RTBMain.TextLength
If position + findInstance.findString.Length < EOF Then
FrmMain.RTBMain.SelectedText = findInstance.replaceString
Else ' prevent error when replacing a selected string with greater length than the selected text near EOF
Dim clipboardContents As String = ""
If Clipboard.ContainsText Then
clipboardContents = Clipboard.GetText
End If
Clipboard.SetText(findInstance.replaceString)
FrmMain.RTBMain.Paste()
If clipboardContents.Length > 0 Then
Clipboard.SetText(clipboardContents)
End If
End If