Jump to content

Sorting through data

- - - - -

  • Please log in to reply
4 replies to this topic

#1
IZZO

IZZO

    Newbie

  • Members
  • Pip
  • 2 posts
My friend and I are in the process of learning C#, Our first project is to try to make a Rcon tool for the game Medal of Honor. What we are stuck on at the moment is how to sort through the data that we receive back from the game server. We have looked in to using arrays but we just don't quite understand how to use them like this. Any help would be greatly appreciated.

Below is the format the server send the data back in.

map: obj/mp_palermo_obj
num score ping name lastmsg address qport rate
--- ----- ---- --------------- ------- --------------------- ----- -----
5 263 74 ToUcHoFdEaTh 50 000.00.000.000:12203 10548 40000
6 268 58 MovingTarget 50 00.00.00.000:12203 50269 20000
7 263 175 ?Gru??loWJo?? 50 000.00.00.000:12203 61265 20000
10 0 69 ?Gru?Rust 50 00.00.000.000:1420 27210 40000
11 268 156 [HI]Mojito 50 00.000.00.00:-3697 13873 40000
12 268 175 -?Gru?-s??r???n 50 000.00.00.000:1024 56343 20000
13 268 151 ?Gru??mi?em???'? 0 00.00.00.000:12203 14714 40000
14 263 50 [HI]Rambo 0 00.000.000.00:12203 59245 40000
17 268 64 [HI]B@D 0 000.000.00.000:12203 23660 40000
18 268 50 ???Mr??[*ADM*]Hei?eN*FD* 0 000.000.00.000:22292 33833 30000
19 263 162 nameless#151 50 000.000.00.00:16139 22889 40000
20 263 74 8thWonder|hxc 0 00.00.000.000:12203 17218 40000

Edited by IZZO, 22 August 2011 - 04:42 PM.


#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
What data are you trying to sort out of that? All of it into an array for each type?
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme
How do you want to sort that data? Like by score or by rate or address?

What I would do first is make a class that represents just one row of that data and then make an array of that. Did post back with how you want to sort it and I can show you how to sort your array! :)

#4
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
I would personally use a StreamReader object to read the data line by line, and pass each line through String.Split(' ') to tokenize the line using the space character as the delimiter. This would return an array of strings, which you could individually call Int32.Parse() with to get an integer value, or whatever parsing method is appropriate depending on what data type that field represents. I'm not sure I understand what the 6th field in your example above is supposed to represent. In theory, you should know what each of the fields represent and what to do with them.

EDIT: If what you're really wanting to do is sort all the lines once they've all been read into an array, then I would suggest using Array.sort(Array, IComparer) and writing your own IComparer interface, so you could specify which field to compare. To clarify: You would have one array which represents all of the records (lines), each loaded into a separate index of the array. This would be the array you call .sort() on. Inside the array, at each index, would be an object that you define yourself to hold all the fields in a record, i.e., the items you parsed from my first paragraph above. You would have to write an IComparer for this object class so your program would know how to compare them (which fields to compare, and what constitutes "higher" or "lower" values in said comparison.)

Here's a couple of documentation pages on the sort(Array, IComparer) method and how to write IComparers:
Array.Sort Method (Array, IComparer)
How to use the IComparable and IComparer interfaces in Visual C#
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#5
IZZO

IZZO

    Newbie

  • Members
  • Pip
  • 2 posts
We want to sort by client number (num, on the left). Our goal is to have that data sorted to a table on the program window.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users