Catching a specific string position from a txt file

Hi I’am loading a .txt file, it has a lot of data, each line has 16 values and i need to read separetly each colum and store in a variable.
Here is what i have try’d

let year;
let data;

function preload(){
  data = loadStrings("data/FDR.txt");
}
function setup() {
  createCanvas(1400, 700);

//with that i have each inf in a string
  let str = join(data, ' ');
  let words = split(data, ' ');
  

  for(let i =0 ; i<words.length ; i+16){
    year = words[i];
  }
  console.log(year);
}

Sample of the file:

2019 8 6 13 16 48 -3.42 -9.64 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 -3.62 -9.53 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 -3.26 -9.11 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 -1.56 -9.71 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 0.82 -9.47 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 3.53 -9.63 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 4.30 -10.43 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 4.59 -12.42 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 3.90 -13.03 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 0.96 -12.43 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 -2.40 -11.68 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 48 -1.55 -11.40 0.00 0.00 905.50 -25.480450 -49.271032 9
2019 8 6 13 16 49 -1.86 -11.32 0.00 0.00 905.40 -25.480462 -49.271028 9
2019 8 6 13 16 49 -0.63 -11.31 0.00 0.00 905.40 -25.480462 -49.271028 9
2019 8 6 13 16 49 -0.90 -10.20 0.00 0.00 905.40 -25.480462 -49.271028 9
2019 8 6 13 16 49 -1.88 -9.20 0.00 0.00 905.40 -25.480462 -49.271028 9
2019 8 6 13 16 49 -2.01 -10.25 0.00 0.00 905.40 -25.480462 -49.271028 9
1 Like

Did you look at loadTable or doesn’t it exist in p5?

1 Like

loadTable exist’s, I haven’t try yet. I still trying to figure out how p5 works haha. thanks

loadTable is with comma separated values but maybe you can use space separated values too

1 Like

example after edit to CSV and give header line, also TSV is possible, [space] not
https://editor.p5js.org/kll/sketches/jZAFXmNV5

3 Likes

Here’s another CSV loadTable() example sketch: :innocent:


p5js.org/reference/#/p5/loadTable

2 Likes