• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

VS2008 VB.NET - Filter text lines in textbox1

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
_ColdFire_
Asked:
_ColdFire_
  • 5
  • 4
1 Solution
 
magicdlfCommented:
       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
 
_ColdFire_Author Commented:
VB.NET Please.
0
 
magicdlfCommented:
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
_ColdFire_Author Commented:
does this code know that he need to get text from textbox?
0
 
magicdlfCommented:
No, you need to pass the textbox.Text to this method. For example:
loadText(TextBox1.Text)
0
 
arunallimuthuCommented:
Hey,

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

Thanks,
Arun
0
 
_ColdFire_Author Commented:
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
 
_ColdFire_Author Commented:
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
 
magicdlfCommented:
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
 
_ColdFire_Author Commented:
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now