Reputation: 21
I have a long TXT string imported into a RichTextBox. I am trying to copy a portion of that text using beginning and end points based on text strings. Here is what I have so far,
Dim StartsearchString As String = "MyStartString"
Dim EndSearchString As String = "MyEndString"
Dim Length As Integer
Dim StartPoint As Integer
Dim EndPoint As Integer
Length1 = Len(StartsearchString)
Length2 = Len(EndSearchString)
StartPoint = Form2.RichTextBox2.Find(StartsearchString) + Length1
EndPoint = Form2.RichTextBox2.Find(EndSearchString) - Length2
How can I copy the text between the Start and End points and paste it into a new RichTextBox?
Thank you.
Upvotes: 0
Views: 127
Reputation: 81620
Your EndPoint is off since you don't have to substract the length of the EndString. That is, the Find method is finding the beginning of that index.
I re-worked it this way using the SubString function:
Dim StartsearchString As String = "MyStartString"
Dim EndSearchString As String = "MyEndString"
Dim StartPoint As Integer = RichTextBox2.Find(StartsearchString)
Dim EndPoint As Integer = RichTextBox2.Find(EndSearchString)
If EndPoint > StartPoint Then
OtherRTB.Text = RichTextBox2.Text.Substring(
StartPoint + StartsearchString.Length,
EndPoint - StartPoint - StartsearchString.Length)
End If
Upvotes: 1