Results 1 to 2 of 2

Thread: Is it possible to do this with a RichTextBox?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    7

    Is it possible to do this with a RichTextBox?

    I'm trying to make a program that will remove lines from a RichTextBox1 if they are longer than 10 characters and put the removed lines into a separate RichTextBox2.

    I'll provide 2 pictures as an example.
    Name:  EXAMPLE 1.jpg
Views: 192
Size:  16.1 KB
    Name:  EXAMPLE 2.jpg
Views: 172
Size:  16.5 KB

    I'm new to programming in general so I don't know exactly how to approach this issue. I think it could be done with a for each statement. Like, "for each line in richtextbox1.lines DO THIS" or something.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,437

    Re: Is it possible to do this with a RichTextBox?

    This sort of stuff collapses down to a few lines thanks to LINQ.
    Code:
    Dim allLines As String() = RichTextBox1.Lines
    Dim longLines As String() = allLines.Where(Function(line) line.Length > 10).ToArray()
    Dim shortLines As String() = allLines.Where(Function(line) line.Length <= 10).ToArray()
    
    RichTextBox1.Lines = shortLines
    RichTextBox2.Lines = longLines
    You could use a loop if you wanted to and that would have been the only option before LINQ but LINQ tends to make this sort of thing more succinct. It might actually execute slower but when this whole task would be measured in milliseconds, it hardly matters.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width