Page 1 of 1
Text / Data help
Posted: Fri Apr 14, 2006 11:18 am
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
Rik
Posted: Fri Apr 14, 2006 5:25 pm
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
Posted: Fri Apr 14, 2006 5:53 pm
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