Ordinare un array

ho dei file testo che contengono anche data e ora secondo il datetime ma anche altri dati separati dal #

vorrei leggerli ed ordinarli per data ed ora come potrei fare ??

Please read

https://documentation.xojo.com/api/files/textinputstream.html

Let’s assume your result (means your textfile) is in myResult, for instance like:

Var myResult as string = t.ReadAll(Encodings.UTF8)

Then you can use the split command on this string:

// Getting all your lines in the text.Document
Var allMyLines() as string = myResult.Split( endOLine )

For each line as string in allMylines
// Getting all your fields in the Array
 Var allMyFields() as string = line.split("#")
 For each field as string in allMyFields
   // do something with each field
  // ...
 Next
Next

But you can as well implement this logic already while you are reading line by line …

Disclaimer: code not tested, as I am not at my MBP, but it should give you the idea.

Nel file di testo la data e ora in che formato è?

in formato sqldatatime

Ok. Allora io farei in questo modo:

  • crea due array di tipo string (es. arrDate e arrAll)
  • leggi l’intero file di testo riga per riga, isola la data e inseriscila nell’array arrDate, e inserisci l’intera riga di testo nell’array arrAll
  • ordina l’array arrDate sulla data, insieme all’array arrAll: arrDate.SortWith(arrAll)

In questo modo hai l’array arrAll (che non è altro che una copia del file di testo) ordinato in base all’array arrDate (per data): elaborando l’intero array arrAll è come elaborare il file di testo ordinato per data.

Spero di essere stato sufficientemente chiaro: in caso contrario fammelo sapere.

Nedi

1 Like

Grazie tante