Question Splitting text

imbart

New member
Joined
Dec 24, 2009
Messages
4
Programming Experience
1-3
Hello there,

I'm trying to make a rcon tool on my own style. If i call up the status of the server i get this as response:

VB.NET:
  1     2   69 e783c1084e329ae25ee4a2a799e38d25 mathieu91^7            50 xx.xxx.xxx.xxx:28960  27148 25000
  2    25  153 59cfd2cdc3bc40006d281655c1db039b Marty^7                 0 xx.xxx.xxx.xxx:28960     3216 25000
  3     0   94 9c967a4f1129a2cd2dfff64e6f131c41 jejebg^7               50 xxx.xxx.xxx.xxx:28960    -348 25000
  4     2   34 b7a8166b69266e3b24bc2e25762813ae XPlayerboyX^7           0 xxx.xxx.xxx.x:-30135   16010 25000
  5    32   57 6cf02017d86795dabbf7d04ff3196936 luki^7                 50 xxx.xxx.xxx.xxx:-31916 -28506 25000
  6    35   31 ec7e1dc39017b7c29077388e692a8a7d Frannyboy^7            50 xxx.xxx.xxx.xx:28960    -19510 25000
  7     5   98 214c2b31a7b357b20604a951852ec04e AssAssIn#MuSLiM^7       0 xxx.xxx.xxx.xxx:28960    183 25000
  8    15   79 e6d587ffd602704b5b21a349eeb902ef REMUS^7                 0 xxx.xxx.xxx.xxx:28960   -14876 25000
  9    52  120 3c37be308f5b73609b78fdc5c4253fb1 Uba^7                  50 xx.xx.xx.xx:2890     -31937 25000
 10     7   86 6ef2a656f665a9c9bc6a00a57a8a1f8b SmEaGol^7              50 xxx.xxx.xxx.xxx:-4208    -22535 25000
 14     5   62 113a2b16f70b6526b7faf38f2057f126 stainless^7            50 xxx.xxx.xxx.xxx:28960  14554 25000
 16    37   93 dc58ceaf80b453e197732a90958a033e Bastel^7                0 xxx.xxxx.xxx.xx:-12723  -11213 25000

I need to split this and give each part of the status (num,score,ping,guid,name,lastmsg,address,qport,rate) his own string.
So i got this code now it works fine i can call up everything with example:
name(4) where this is the name of the 5th line or address(2) where this is the address of the 3th line.

VB.NET:
        Dim text As String = TextBox1.Text

        text = text.Replace("  ", " ")

        Dim s() As String = text.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)

        Dim num As List(Of String) = New List(Of String)
        Dim score As List(Of String) = New List(Of String)
        Dim ping As List(Of String) = New List(Of String)
        Dim guid As List(Of String) = New List(Of String)
        Dim name As List(Of String) = New List(Of String)
        Dim lastmsg As List(Of String) = New List(Of String)
        Dim address As List(Of String) = New List(Of String)
        Dim qport As List(Of String) = New List(Of String)
        Dim rate As List(Of String) = New List(Of String)

        Try
            For i = 0 To s.Length - 1 Step 9
                num.Add(s(i + 0))
                score.Add(s(i + 1))
                ping.Add(s(i + 2))
                guid.Add(s(i + 3))
                name.Add(s(i + 4))
                lastmsg.Add(s(i + 5))
                address.Add(s(i + 6))
                qport.Add(s(i + 7))
                rate.Add(s(i + 8))
            Next
        Catch ex As Exception
            MsgBox("Error! Malformed text!" + vbCrLf + ex.Message, MsgBoxStyle.Critical, "text split")
            Exit Sub
        End Try

But i got one problem. If it gives a status of example:
4 136 79 3169f89ec64a9ba0e7e5521b872f9c6f [EHS] SAJ^7 50 xx.xxx.xxxx.xx:28960 29953 25000
Then the name has a space between it and the program gives me the malformed text error. Now is it possible to edit this code that it splits my text just as it does here but that it splits just the name at the '^7' which is behind every name?
Any other kind of solution is very helpful too!

Thanks.
 
Last edited:
I would use a custom object nested in your original class like:
VB.NET:
Public Class myXclass
   Public num As String
   Public score As String
   Public ping As String
   Public guid As String
   Public name As String
   Public lastmsg As String
   Public address As String
   Public qport As String
   Public ra_te As String
End Class
 ' then you only need a List(Of myXclass)
Dim xClass As New List(Of myXclass)
Much neater code, now in your loop add the elements - xClass.name = something. Also I would Regex to get the groups rather than split the string.
 
I might be crunched for time - being the holidays(and my B-day) and all, but I will get something back as soon as I can if noone else does.
 
Sure but that Load function is a fun one. Glad it works.
 
Last edited:
Back
Top