Results 1 to 2 of 2

Thread: [Urgent] String Manipulation Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    2

    [Urgent] String Manipulation Help

    Hi,

    Im pretty new here and I need a hand splitting a string into parts to insert into a table (Data Grid View).

    The string is as follows
    Code:
    map: mp_shipment
    num score ping guid                             name            lastmsg address               qport rate
    --- ----- ---- -------------------------------- --------------- ------- --------------------- ----- -----
      0     0    7 719f826a9a7ee795ed3c43********** Not Yourself^7          0 127.0.0.1:28961       30793 25000
    As you can see its for a game (Cod4) I am making a rcon tool. It is all going well apart from splitting the string.

    What i need help with is putting the (num, GUID, Name and address) for each person (im showing only one) into a DGV.

    Could anybody help me please.

    Thank you
    Adam
    Last edited by damaster1901; Jun 18th, 2012 at 04:36 AM. Reason: Contained Personal details

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: [Urgent] String Manipulation Help

    The following obtains column data by ordinal position. Three columns on the line must be numeric based on the line you provided and if this is not correct you need to correct it. In short this gives you a method to populate a unbound DataGridView.

    Code:
    Dim Lines = IO.File.ReadAllLines("Your file name goes here")
    Dim MapNumber As Integer = 0
    Dim Score As Integer = 0
    Dim LastMsg As Integer = 0
    
    For Each line In Lines
        If Integer.TryParse(line.Substring(0, 3), MapNumber) AndAlso
            Integer.TryParse(line.Substring(3, 6), Score) AndAlso
            Integer.TryParse(line.Substring(64, 9), LastMsg) Then
    
            DataGridView1.Rows.Add(New Object() _
                                   {
                                       MapNumber,
                                       Score,
                                       line.Substring(15, 32),
                                       line.Substring(48, 14),
                                       LastMsg,
                                       line.Substring(75, 14)
                                    }
                                )
        End If
    Next

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