I'm working on a project in which I need to display textual trees. I'm trying to use Java's String.format method to simplify the formatting process, but I ran into trouble when trying to apply variable widths.
Current I have a variable (an int) which is called depth.
I try to do the following:
String.format("%"+depth+"s"," ") + getOriginalText() + "\n";
However I get the following error.
java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags = 0
Any suggestions on how to do this, or should I just settle for loops?
Thanks for the help!
*modifier:The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted., i.e. I was searching for something likeString.format( "%*i", pad_width, number ). But the given answer makes sense, too.