# Catching a specific string position from a txt file

**URL:** <https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685>\
**Category:** Coding Questions\
**Created:** [August 29, 2019, 1:34pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685 "2019-08-29T13:34:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuilhermeVolker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/guilhermevolker/32/5657_2.png) [@GuilhermeVolker](https://discourse.processing.org/u/GuilhermeVolker)\
**Post date:** [August 29, 2019, 1:34pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685/1 "2019-08-29T13:34:40Z")

</div>

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

```auto
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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 29, 2019, 2:06pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685/2 "2019-08-29T14:06:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GuilhermeVolker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/guilhermevolker/32/5657_2.png) [@GuilhermeVolker](https://discourse.processing.org/u/GuilhermeVolker)\
**Post date:** [August 29, 2019, 2:20pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685/3 "2019-08-29T14:20:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 29, 2019, 2:25pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685/4 "2019-08-29T14:25:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 29, 2019, 2:26pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685/5 "2019-08-29T14:26:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 29, 2019, 3:04pm UTC](https://discourse.processing.org/t/catching-a-specific-string-position-from-a-txt-file/13685/6 "2019-08-29T15:04:36Z")

</div>

Here’s another CSV **loadTable()** example sketch: 😇

> [@Reducing points in polygon](https://discourse.processing.org/t/reducing-points-in-polygon/13590/6):
>
> For completeness’ sake, I’ve ended up making a p5js version too: crazy_face

> <https://gist.github.com/GoSubRoutine/da4939559d8b786df13f5694ea2edd30>
>
> There are more than three files. show original

> **[reference | p5.js](https://p5js.org/reference/#/p5/loadTable)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.
