Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in appending spaces to string

 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

now its adding 32 spaces..
will that be ok
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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").
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic