Text / Data help

Just starting out? Need help? Post your questions and find answers here.
Rikuk
User
User
Posts: 24
Joined: Mon May 30, 2005 11:36 am

Text / Data help

Post by Rikuk »

Hi I've a text file that contains the following information

Date,League,Home Team,Away Team,Home Win%,Draw%,Away Win%

What's the best way of loading this data into Purebasic and sort & manipulate the data?

Thanks in advance for any thoughts ideas ect.

Examples would be much appriacted
:D

Rik
mike74
User
User
Posts: 60
Joined: Mon Nov 21, 2005 1:44 pm

Post by mike74 »

Hi Rik,

It's hard to say what the "best" way of doing anything is, particularly if you do not specify how you define best, but one way to approach this is the following:

1. Use ReadString to read a file line.

2. Parse the line using StringField with commas as separators (assuming there are no commas in the "values").

3. Put the "values" into a structured array.

4. Repeat steps 1 to 3 until EOF is reached.

5. Use SortStructuredArray to sort the data.

I'm sure you can find lots of examples by searching the forums, PB Help file, and example sources in the directory/folder where you installed PB.


Mike
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

this is how i always do such situations :
( which is almost what mike74 explained ;-) )

Code: Select all

line$ = "Date,League,Home Team,Away Team,Home Win%,Draw%,Away Win%"

NewList value.s()

Repeat
  
  i + 1
  
  value$ = StringField(line$, i, ",")
  
  If value$
    AddElement(value()) : value() = value$
  EndIf
  
Until value$ = ""

SortList(value(),2)

ForEach value()
  Debug value()
Next
or this way if you know the number of item in one line :

Code: Select all

line$ = "Date,League,Home Team,Away Team,Home Win%,Draw%,Away Win%"

#nbItem = 7

Dim item.s(#nbItem)

For i = 1 To #nbItem
  item(i) = StringField(line$, i, ",")
Next

SortArray(item(),2)

For i = 1 To #nbItem
  Debug item(i)
Next
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply