java - how to nicely indent when the \t is incorrect. -
i'm trying have indentation correct. in code below, s2 comes database , output console (system.out.println). in fact, s2 list of objects , s2 tostring indentation. simplicity issues, consider following code:
public class testindent { public static void main(string[] args) { string s1 = "case num\ttype\tref date\tamount"; string s2 = "9157120183\tppaq\t*** ref date not exists! ***\t$95.00"; system.out.println(s1); system.out.println(s2); } } the output be:
case num type ref date amount 9157120183 ppaq *** ref date not exists! *** $95.00 my desire have indent correctly this:
case num type ref date amount 9157120183 ppaq *** ref date not exists! *** $95.00 you note 'amount' right on top of number (which correct place). before i'm writing class indent based on max length of string, wondering if exists problem.
a tab character single character render differently in different environments inherently hard use - looks nice on console may fine on mine, or poo on lee meador's has 8 character wide tabs.
you use sotirios's suggestion creating function pad headers spaces - can trust spaces. of course if console not using fixed width font can not rely on either - better.
you use javas inbuilt string formatting reduce need manual calculation if know how wide want display columns, truncate long values, e.g:
system.out.printf("%-10.10s %-6.6s %-30.30s %-10.10s%n", "case num", "type", "ref date", "amount"); system.out.printf("%-10.10s %-6.6s %-30.30s %-10.10s%n", "9157120183", "ppaq", "*** ref date not exists! ***", "$95.00"); or leave output tab separated or comma separated , write file , let program designed rendering these things deal it.
Comments
Post a Comment