File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes problem in appending spaces to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in appending spaces to string" Watch "problem in appending spaces to string" New topic
Author

problem in appending spaces to string

swapnel surade
Ranch Hand

Joined: Mar 05, 2009
Posts: 129
hi all,

I have one string to which I have to append few spaces at the end.

I tried to use




but it appending spaces at the start.

is there any way to append spaces at the end of the string.

thanks.
harilal ithikkat
Ranch Hand

Joined: Oct 06, 2008
Posts: 221

now its adding 32 spaces..
will that be ok


SCJP 1.5
"A candle looses nothing by lighting another candle"
itechmentors.com
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2969
    
    9
Swapneel: what you want is "left justification", pushing the string contents up against the left side of the field you've allocated for them. Which means you add spaces on the right side, which is to say, the end of the string. This is achieved in Java string formatting using a '-' flag. Try something like String.format("%-32s", "jack").
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in appending spaces to string
 
Similar Threads
Can someone spot an error here?
Inefficient code
StringBuffer
int can not be dereferenced means what
How to trim spaces between characters of string using javascript