Results 1 to 9 of 9

Thread: Splitting text

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    11

    Splitting text

    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:

    Code:
      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.

    Code:
            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 by imbart; Dec 24th, 2009 at 07:48 PM. Reason: IP's removed

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Splitting text

    Sometimes is neccesary to use a combination of functions as : Split, SubString, IndexOf, InStr and InStrRev
    You could get that portion using InStr and SubString or InStrRev

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    11

    Re: Splitting text

    Thanks for your reply, I will try something.
    If you got a little time left to help me with a little example code could be very helpful.
    If not I hope I can figure it out.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    11

    Re: Splitting text

    Ok I got it to work, Thanks

  5. #5
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Splitting text

    InStr is legacy code, do not use legacy code.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    11

    Re: Splitting text

    I didn't use it

  7. #7
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Splitting text

    'InStr' is a VB.NET method that is neither deprecated nor obsolete

  8. #8
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Splitting text

    InStr, Mid, LBound, UBound, these are all from VB6 and are only still available for backward compatibility. That doesn't mean they are relevant. There is no reason not to use framework classes and methods, especially when we are currently at VB9.

  9. #9
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Splitting text

    InStr, Mid, LBound, etc should all be mark obsolete at this point. There's no reason for any of them at all anymore.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

Tags for this Thread

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