none
Taking specific values from richtextbox RRS feed

  • Question

  • Hi,

    I'm trying to take specific data from richtextbox to another, here is the example;

    Richtextbox1 holds data like;

    a0000

    b0000

    c0000

    d0000

    a1111

    b1111

    c1111 and so,

    have to take for example values which begin with a . then I will cut them and paste another rich textbox.

    Monday, January 14, 2019 1:23 PM

Answers

  • Hi

    Here is one way, there are many.

    This is a test stand alone example. Give it a try to see if it helps.

    Image

    Code

    ' Form1 with RichTextBox1, RichTextBox2,
    ' TextBox1, Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        RichTextBox1.AppendText("a0000" & vbCrLf)
        RichTextBox1.AppendText("b0000" & vbCrLf)
        RichTextBox1.AppendText("c0000" & vbCrLf)
        RichTextBox1.AppendText("d0000" & vbCrLf)
        RichTextBox1.AppendText("a1111" & vbCrLf)
        RichTextBox1.AppendText("b1111" & vbCrLf)
        RichTextBox1.AppendText("c1111")
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim txt, txt2 As New List(Of String)
        txt = RichTextBox1.Lines.ToList
        For i As Integer = txt.Count - 1 To 0 Step -1
          If txt(i).StartsWith(TextBox1.Text) Then
            txt2.Add(txt(i))
            txt.RemoveAt(i)
          End If
        Next
        txt2.Reverse()
        RichTextBox1.Lines = txt.ToArray
        RichTextBox2.Lines = txt2.ToArray
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, January 14, 2019 4:36 PM Amended code
    • Marked as answer by Abdurrahman YAMAN Tuesday, January 15, 2019 7:00 AM
    Monday, January 14, 2019 3:06 PM

All replies

  • Hello,

    Please show code of your efforts so far so we can guide you in this task. And please make sure to include any details not presented in your current question as this will help others help you.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, January 14, 2019 1:37 PM
    Moderator
  • Hi

    Here is one way, there are many.

    This is a test stand alone example. Give it a try to see if it helps.

    Image

    Code

    ' Form1 with RichTextBox1, RichTextBox2,
    ' TextBox1, Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        RichTextBox1.AppendText("a0000" & vbCrLf)
        RichTextBox1.AppendText("b0000" & vbCrLf)
        RichTextBox1.AppendText("c0000" & vbCrLf)
        RichTextBox1.AppendText("d0000" & vbCrLf)
        RichTextBox1.AppendText("a1111" & vbCrLf)
        RichTextBox1.AppendText("b1111" & vbCrLf)
        RichTextBox1.AppendText("c1111")
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim txt, txt2 As New List(Of String)
        txt = RichTextBox1.Lines.ToList
        For i As Integer = txt.Count - 1 To 0 Step -1
          If txt(i).StartsWith(TextBox1.Text) Then
            txt2.Add(txt(i))
            txt.RemoveAt(i)
          End If
        Next
        txt2.Reverse()
        RichTextBox1.Lines = txt.ToArray
        RichTextBox2.Lines = txt2.ToArray
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, January 14, 2019 4:36 PM Amended code
    • Marked as answer by Abdurrahman YAMAN Tuesday, January 15, 2019 7:00 AM
    Monday, January 14, 2019 3:06 PM
  • It helps a lot. Thank you!
    Monday, January 14, 2019 4:10 PM
  • Hi,

    Do you resolve the issue? If you resolve the issue,please mark the helpful as answer. 

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 15, 2019 2:09 AM