Text() don't recognize \t tabulator

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:

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

1 Like

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

hardcoded tabstops?

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);
}

1 Like

Is this actually https://github.com/processing/processing/issues/5625 ?

2 Likes

Yes, Thanks so much kll, your limited help is useful.

Thanks neilcsmith

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

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++;
} 

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.

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()

thanks to everyone.

2 Likes

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.

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
//
3 Likes

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

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

4 Likes

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

2 Likes

good, although in this example print by console…

how about this example:
Storing String Data in Arrays? ?
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.

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);

}


1 Like

I apologize 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:

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.

1 Like

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

1 Like

Ok, thank you GoToLoop, I will do so.