?
Solved

VS2008 VB.NET - Filter text lines in textbox1

Posted on 2010-01-11
10
Medium Priority
?
303 Views
Last Modified: 2013-11-26
Hi I would like to know, how to filter text inside textbox1.text. My application is reading textbox of another application and shows it in my textbox. How to filter textbox of my application so it shows only specific lines not everything

Example (Application from which text is readed)

[09:03:55] <TheWizard-_-> Sometext
[09:03:55] <TheWizard-_-> Sometext
[09:03:55] <TheWizard-_-> Sometext
[09:04:30] [System Message] <ma7moud123>[Ping:31]  has joined your game!.
[09:03:55] <TheWizard-_-> Sometext
[09:03:55] <TheWizard-_-> Sometext
[09:04:46] [System Message] <ma7moud123>  has left your game!(4).
[09:03:55] <TheWizard-_-> Sometext

and that all appears in my program, textbox1.text.
[09:04:30] [System Message] <ma7moud123>[Ping:X]  has joined your game!.
[09:04:46] [System Message] <ma7moud123>  has left your game!(4).

So it displays only leave and join messages.

I need to filter it and display like this:


0
Comment
Question by:_ColdFire_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 9

Expert Comment

by:magicdlf
ID: 26281728
       void loadText(string str)
        {
            string[] lines = str.Split(new char[] { '\n' });
            StringBuilder sb = new StringBuilder();
            foreach (string line in lines)
            {
                if (line.Contains("[System Message]"))
                {
                    sb.AppendLine(line);
                }
            }
            TextBox1.Text = sb.ToString();
        }
0
 

Author Comment

by:_ColdFire_
ID: 26282186
VB.NET Please.
0
 
LVL 9

Accepted Solution

by:
magicdlf earned 2000 total points
ID: 26282317
Private Sub loadText(ByVal str As String)
    Dim lines As String() = str.Split(New Char() {ControlChars.Lf})
    Dim sb As New StringBuilder()
    For Each line As String In lines
        If line.Contains("[System Message]") Then
            sb.AppendLine(line)
        End If
    Next
    TextBox1.Text = sb.ToString()
End Sub
0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 

Author Comment

by:_ColdFire_
ID: 26282354
does this code know that he need to get text from textbox?
0
 
LVL 9

Expert Comment

by:magicdlf
ID: 26282361
No, you need to pass the textbox.Text to this method. For example:
loadText(TextBox1.Text)
0
 
LVL 2

Expert Comment

by:arunallimuthu
ID: 26282371
Hey,

The best way to achieve this, use regular expression and find the string.

Thanks,
Arun
0
 

Author Comment

by:_ColdFire_
ID: 26282552
I will accept your solution as it worked, but i have a few more questions so you maybe want to have a look on them. Same section.
0
 

Author Comment

by:_ColdFire_
ID: 26282661
also, how to check what kind of system message it is, there are 2 different types, one is when player joins and leaves, the other ones are like this:

[12:40:59] [System Message] <aleksmkd>  Ping: 94ms  Map: [TeamCircleGoldSeriesv2[1][1].2.w3x]

That somebody created a map, how to make filter to not show those messages?
0
 
LVL 9

Expert Comment

by:magicdlf
ID: 26282723
So you just want to show the join and leave messages.
Private Sub loadText(ByVal str As String)
    Dim lines As String() = str.Split(New Char() {ControlChars.Lf})
    Dim sb As New StringBuilder()
    For Each line As String In lines
        If line.Contains("[System Message]") AndAlso ((line.Contains("join") OrElse line.Contains("left"))) Then
           sb.AppendLine(line)
        End If
    Next
    TextBox1.Text = sb.ToString()
End Sub
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question