# Text() don't recognize \\t tabulator

**URL:** <https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572>\
**Category:** Coding Questions\
**Created:** [March 24, 2019, 11:52am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572 "2019-03-24T11:52:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 24, 2019, 11:52am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/1 "2019-03-24T11:52:02Z")

</div>

Hi friends,  
I’ve a problem with the tab…  
the function text() doesn’t recognize \t while the funcion print() if it does.

you can see a simple code:

```auto
String datos[]=new String[10];
int sep=15;
datos=loadStrings("Datos.txt");

size(400,200);
text("Datos\ttabulados",10,30);
for (int i=0;i<datos.length;i++){
 text(datos[i],10,30+sep);
 println(datos[i]);
 sep+=15;
}

```

I have looking for topics, but I have looking for information.

Can someone give me an idea?, please.  
I’m using Processing 3.3.7  
Thanks.

Maybe you need the Datos.txt:

[https://drive.google.com/file/d/1nJvVXOA1efbR1uOSclc9CbjWDVO3G9jX/view?usp=sharing](https://drive.google.com/file/d/1nJvVXOA1efbR1uOSclc9CbjWDVO3G9jX/view?usp=sharing)

 ![Captura](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/51ee1973be0252a2a1bd6db78c40f746a76cb1a8.png)

---

<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:** [March 24, 2019, 3:27pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/2 "2019-03-24T15:27:44Z")

</div>

yes, right,  
while a \n (newline) is understood a \t not,  
but i try a split on it ( might be of limited help )

 ![SNAG-0021](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/ef5ddbeb520671eb1724dc4b528e8f2ae97044fc.jpeg)

hardcoded tabstops?

```auto
String[] datos = loadStrings("data/Datos.txt");
int[] tabstop={25,100,180,220,250,280,310,340,370};
size(500,500);
fill(0);
for (int k = 0; k < datos.length; k++ ) {
  String line = datos[k];
  String[] tabs = split(line, '\t');
  for (int i =0;i<tabs.length;i++ ) {
    String t = tabs[i];
    text (t, tabstop[i], (k+1)*20);
  }
  println(line);
}

```

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [March 24, 2019, 5:49pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/3 "2019-03-24T17:49:12Z")

</div>

Is this actually [https://github.com/processing/processing/issues/5625](https://github.com/processing/processing/issues/5625) ?

---

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 25, 2019, 6:04pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/4 "2019-03-25T18:04:31Z")

</div>

Yes, Thanks so much [kll](https://discourse.processing.org/u/kll), your limited help is useful.

---

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 25, 2019, 6:06pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/5 "2019-03-25T18:06:07Z")

</div>

Thanks [neilcsmith](https://discourse.processing.org/u/neilcsmith)

---

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 26, 2019, 9:22am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/6 "2019-03-26T09:22:23Z")

</div>

and then, for to load from an array this would be a code.  
Don’t abbreviate it anymore…

```auto
String []lineas=loadStrings("Datos.txt");
String tabs[]=new String[lineas.length];
size(600,300);
int x=0,y=0;
for (String t:lineas){
  for(String tb:tabs=split(t,'\t')){
    text(tb,10+x*70,60+y*20);
    x++;
  }
  x=0;
  y++;
} 

```

 ![Captura2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f803fb55f1d6372e6bbf52296bb42ba60f69c93e.png)

Actually what I was looking for was an overprint of the data, as a visual support to the data that could already be seen graphically, the following code shows it, although I preferred to print a block with each data in a different line and then go over writing this whole block.

```auto
String []lineas;
String tabs[];
int x=0,y=0,frame;
void setup(){
  size(300,300);
  lineas=loadStrings("Datos.txt");
  tabs=new String[lineas.length];
  frameRate(100);
}// cierra setup()
void draw(){
 if(frame<lineas.length){ // The screenshot show 1440; it is my files of everyday
   background(125); 
   String t=lineas[frame];
   for(String tb:tabs=split(t,'\t')){
     text(tb,10,60+y*20);
     y++;
   }
   y=0;
   frame++;
 }else{background(125);text("The End",10,60);}
}// cierra draw()

```

 ![Captura_2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3aea829aae594e0aeec271130106bfd5cbad58e0.png)

thanks to everyone.

---

<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:** [March 26, 2019, 9:47am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/7 "2019-03-26T09:47:39Z")

</div>

coming back to the version with tabs (table)

it’s always clearer when we make a function `textWithTabs` (in this case) that does the work.

The code is clearer then because you have the function as an entity of its own.

```auto
String[] lineas;

void setup() {
  size(1300, 500);
  lineas = loadStrings("Datos.txt");
} // end setup()

void draw() {
  background(125); 

  int y=0;
  for (String t : lineas) {
    textWithTabs ( t, 
      30, 20*y + 120 ); 
    y++;
  }//for
}// end draw()

void textWithTabs(String t_, 
  int x_, int y_) {

  int xPos=0;
  String[] tabs = split(t_, "\t");

  for (String tb : tabs) {
    text(tb, 
      110*xPos+x_, y_);
    xPos++;
  }//for
  //
}// end func
//

```

---

<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:** [March 26, 2019, 9:48am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/8 "2019-03-26T09:48:45Z")

</div>

happy you got it the way you need,

but i still want to mention that as you have tab separated data file  
a much better way as reading and split as string would be  
use the  
[https://processing.org/reference/loadTable\_.html](https://processing.org/reference/loadTable_.html)

```auto
Table datos = loadTable("Datos.txt", "tsv"); 

```

and you got a smarter array ( with a different syntax to deal with )  
[https://processing.org/reference/Table.html](https://processing.org/reference/Table.html)

---

<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:** [March 26, 2019, 10:27am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/9 "2019-03-26T10:27:32Z")

</div>

Another good alternative is to display the data via a separate JTable: 💡

> [@Filling Dinamyc Arrays\[\]\[\]](https://discourse.processing.org/t/filling-dinamyc-arrays/7049/5):
>
> That makes the code lighter. No need for [TableColumn](http://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/table/TableColumn.html#%3Cinit%3E(int)) this time. sweat_smile Just a simple call to JTable::updateUI() instead after appending a new row to the grid container: call_me_hand[Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JTable.html#updateUI()](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JTable.html#updateUI()) Here’s the new version of “JTable Example” that dynamically appends rows instead of columns: wink /\*\* \* JTable Example II (v1.0.2) \* GoToLoop (2019/Jan/01) \* https://Discourse.Processing.org/t/filling-dinamyc-…

---

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 26, 2019, 11:57am UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/10 "2019-03-26T11:57:13Z")

</div>

good, although in this example print by console…

---

<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:** [March 26, 2019, 1:02pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/11 "2019-03-26T13:02:50Z")

</div>

how about this example:  
[Storing String Data in Arrays?](https://discourse.processing.org/t/storing-string-data-in-arrays/9347/11) ?  
sorry that code is for a file with a header line,  
and contains a cell editor you might not need

anyhow you never tell us where you get that data file from,  
can it be created as

- CSV ( “,” separator ) and also named .csv
- have a meaningful header line

once the data are in a table ( array ) the output for swap rows / columns  
should be more easy.

```auto
Table datos; 

void setup() {
  size(500,500);
  datos = loadTable("data/Datos.txt", "tsv"); 
//}

// void draw() {
  background(0);
  for (int r = 0;r < datos.getRowCount() ; r++) for (int c =0;c < datos.getColumnCount() ; c++) text(datos.getString(r,c),10+c*60,(r+1)*20);
// for (int r = 0;r < datos.getColumnCount() ; r++) for (int c =0;c < datos.getRowCount() ; c++) text(datos.getString(c,r),10+c*70,(r+1)*20);

}

```

 ![SNAG-0023](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f5b2b1eb8b5a2627ae0e7643a56b4c6d167e6f4b.jpeg)  
 ![SNAG-0022](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/ed6e80fcdedf3fea720c0f9bade45c0e62e40a79.jpeg)

---

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 26, 2019, 2:20pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/12 "2019-03-26T14:20:48Z")

</div>

I apologize [kll](https://discourse.processing.org/u/kll) , the source file is a plain text file, “Datos.txt” that is identical to the one I attach, but with 1440 lines, it hasn’t header and the elements are separated with tabs.  
The examples that you have given me I am saving them, they are interesting and I sure need them for another occasion.  
I needed the data in the sketch, the result of this tip is the following:

 ![PNG](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/424a8618272b19d4f60dfa20029de4cbff8c7048.jpeg)

It’s the black rect() to the left of the image.  
It’s an automatic reproduction that shows the meteorological records along with its image (one per minute)  
Thanks so much.

---

<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:** [March 26, 2019, 5:01pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/13 "2019-03-26T17:01:31Z")

</div>

> [@Santy](#):
>
> “Datos.txt” is identical to the one I had attached, but with 1440 lines, no header and its elements are separated with tabs.

W/ those characteristics, that file’s extension should be renamed as a “.tsv” instead ➡ “Datos.tsv”, in order to better represent its content:

> **[Tab-separated values](https://en.wikipedia.org/wiki/Tab-separated_values)**
>
> Tab-separated values (TSV) is a simple, text-based file format for storing tabular data. Records are separated by newlines, and values within a record are separated by tab characters. The TSV format is thus a delimiter-separated values format, similar to comma-separated values.
> TSV is a simple file format that is widely supported, so it is often used in data exchange to move tabular data between different computer programs that support the format. For example, a TSV file might be used to transfe...

---

<div class="post-metadata">

**Author:** ![Santy](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Santy](https://discourse.processing.org/u/Santy)\
**Post date:** [March 26, 2019, 5:18pm UTC](https://discourse.processing.org/t/text-dont-recognize-t-tabulator/9572/14 "2019-03-26T17:18:48Z")

</div>

Ok, thank you [GoToLoop](https://discourse.processing.org/u/GoToLoop), I will do so.
