wood burning stoves
The moose likes Beginning Java and the fly likes padding strings - left and right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "padding strings - left and right" Watch "padding strings - left and right" New topic

padding strings - left and right

Thomas Bigbee
Ranch Hand

Joined: Nov 29, 2001
Posts: 48
In the xbase languages there are a number of string functions that I used all the time - padl (pad left) - padr (pad right) and alltrim() - additionally - padl and padr would take two or three parameters - the string to be padded, the length of the new string and optionally the pad character (default to spaces)
do these constructs exist in java? example...
local strTest = " abc "
strTest = padl(alltrim(strTest), 4)
strTest == " abc"
I could create my own class to do this but don't want to reinvent the wheel - any help would be appreciated
Thank you, Tom Bigbee
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Thomas,
I think that the StringBuffer class, using insert(int offset, char c) and append(char c) should help.
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
I have written those functions into my StringHelper class. http://ostermiller.org/utils/StringHelper.html
Thomas Bigbee
Ranch Hand

Joined: Nov 29, 2001
Posts: 48
Thank you, that's just what I was looking for
I agree. Here's the link: http://aspose.com/file-tools
subject: padding strings - left and right
It's not a secret anymore!