This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying to return a string made up of several different concatenated variables of multiple types to a different class. This part is working just fine, the problem is I want the data to show up in neat organized columns in the output from the second program.
The first column of the output is made up of 4 digit numbers...no problem there - I can line that up every time with no problem. The second column is what is causing me problems. It can be between 1 and 20 characters (I set a maximum length of 20 characters of returned input from user's entry) so it is impossible to use a fixed number of spaces to line it up (ie... " " (4 spaces)). Is there a way to set up a variable number of spaces to be displayed, similar to System.out.Printf()'s functionality?
What would be perfect would be if I could set up a statement like -
20 - stringlength = number of spaces to display
Here is the relevant code I have so far with my current (sad) absolutely specified number of spaces...
Add code tags to retrieve spacing. CR[/edit] [ December 04, 2008: Message edited by: Campbell Ritchie ]
Joined: Nov 18, 2008
looks like the extra spaces between the quotes got taken out, but suffice it to say that there were different numbers between each set of quotes.
Somebody else had a similar problem yesterday. Here. I think the printf method and the % tags with widths will help.
Joined: Oct 13, 2005
Originally posted by C Bick: looks like the extra spaces between the quotes got taken out, but suffice it to say that there were different numbers between each set of quotes.
You ought to have used the code button; that would have preserved the spaces.
Joined: Oct 13, 2005
I have edited your post to add code tags, and your spacing has reappeared. You do realise you can set widths and left-justified or right-justified with the printf method? You can also set up a for loop to count spaces and add them together, but I don't think much of that solution.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com