space out strings in processing

how do i space out strings in processing?

example: Employee id Employee Name hours worked

                      1                      bob                    40

Here's my source code

// load the employee file
String[] id = loadStrings("id.txt");

 for(int i = 0; i < id.length; i++)
   println(id[i]);

 // load the employee file
 String [] employeename = loadStrings("employeename.txt");
 for(int i = 0; i < employeename.length; i++)
   println(employeename[i]);

 String [] hoursworked = loadStrings("hoursworked.txt");

 for(int i = 0; i < hoursworked.length; i++)
   println(hoursworked[i]);
Tagged:

Answers

  • how do make the text horizontal?

  • println(...) will print something and move the text insertion point to the start of the next line. Try using print(...) , this will still print something but will leave the text insertion point at the end of the print so

    print("Quark ");
    println("comes");
    print("to the");
    println(" rescue");
    

    displays

    Quark comes    
    to the rescue
    
  • edited April 2018

    i want it to be horizontal like this

    employee id     employee name         
      1                         bob                                      
    
  • Answer ✓

    So some of your statements will use print and the last item on the line will use println try it!

  • ok, thanks

  • edited April 2018

    @Maaother -- are you trying to display visually aligned tabular data, like this?

    id      foo     bar     baz
    1       apple   uno     yut
    2       banana  dos     yee
    3       cherry  tres    sam
    

    ...and are you trying to make it visually aligned just in the console, on the display canvas and in the console?

  • Yeah, I think

    +“\t“+ could be useful in the console but not in the canvas; it’s a tab.

    In the canvas you need some kind of array so each column knows its position

Sign In or Register to comment.