B4J Question Printing columns to terminal

mbenam

Member
Hello all. How can I achieve the following result in b4J? Here is some java code.
Code:
Object[][] a = {
    {1, 3800.20, 2200.42},
    {2, 2700.67, 3678.14},
    {3, 2900.00, 2694.47}
};
System.out.printf("%3s  %-9s  %-9s%n", "Day", "Car1", "Car2");
for (Object[] r : a) {
    System.out.printf("%-3d  %-9.2f  %-9.2f%n", r[0], r[1], r[2]);
}

And here is the output in the terminal.
Output:
Day  Car1       Car2     
1    3800.20    2200.42 
2    2700.67    3678.14 
3    2900.00    2694.47
 

mbenam

Member
Solved it like this. Hope it helps others.
Print at specific column:
Sub AppStart (Args() As String)
    
    Log(AddSp("Arkansas", 12) & AddSp("Arizona", 30) & "Alaska")
    StartMessageLoop
    
End Sub

Sub AddSp (s1 As String, n1 As Int) As String
    s1 = s1 & "                                             " 'Add a fixed number of spaces
    s1 = s1.SubString2 (0, n1) 'Trim the string back to the required length as set by n1
    Return (s1) ' return the result.
End Sub
 
Upvote 0
Top