Use loadTable with variable like String, String[], String[][], StringList?

Hello @jeremydouglass,

I updated code to remove this in Processing 4.01b:

The type StringBufferInputStream is deprecated

I had some fun with it to stimulate my brain:

/**
 * String to Table
 * 2019-07 Processing 3.4
 * discourse.processing.org/t/use-loadtable-with-variable-like-string-string-string-stringlist/12457/6
 */
 
/**
 * Modified by glv
 * 2022-11-27 Processing 4.01
 */


//Reference:
// https://stackoverflow.com/questions/62241/how-to-convert-a-reader-to-inputstream-and-a-writer-to-outputstream 
 
import java.io.ByteArrayInputStream;

Table table;
String tableStr = "";

void setup() 
  {
  size(620, 300);
  background(0);
  
  textSize(24);
    
// Create some data for table
  for (int row = 0; row<10; row++)
    {
    for (int col = 0; col<10; col++)
      {
      if (col == 0)
        tableStr += row + ",";  
      else if (col == 5)
        tableStr += "Really wide text!" + ",";           
      else
        tableStr += col*10.0 + ",";   
      }
    tableStr += "\n"; 
    }
    
  println(tableStr);      
    
  try 
    {
    table = new Table(new ByteArrayInputStream(tableStr.getBytes("UTF-8")), "csv");
    }
  catch (IOException e) 
    {
    }
  
  // Output to console
  for (TableRow row : table.rows()) 
    {
    for (int col=0; col<row.getColumnCount(); col++) 
      {
      print(row.getString(col), " ");
      }
    println("");
    }
      
  // Outout text to sketch window    
  for (int row=0; row<table.getRowCount(); row++) 
    {
    int x = 10;  
    for (int col=0; col<table.getColumnCount(); col++) 
      {
      int y = row;
      text(table.getString(row, col), x, 30*y+20); // May have to account for different string lengths!
      x += textWidth(table.getString(row, col)) + 10;
      }
    }  
    
  noLoop();
  }

image

:)