Results 1 to 3 of 3
  1. #1
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default How to do this with Java Formatter?

    Hi,

    I'm looking for a quick way to cap a String to a x number of characters, and at the same time, if the said String has less than x characters I would like to fill up the String with blanks so that its length becomes x.

    Some examples (x = 20 chars):

    "The brown fox"
    should say: "The brown fox_______"

    "The brown fox jumps over jumps over the lazy dog."
    should say: "The brown fox jumps "

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    Concatenate 20 spaces to the string and then take a substring of the first 20 characters.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

Similar Threads

  1. Developing Word Writter and Formatter
    By Anchal in forum AWT / Swing
    Replies: 1
    Last Post: 04-06-2010, 03:35 AM
  2. Formatter with JOptionPane
    By sweetpea123 in forum Advanced Java
    Replies: 12
    Last Post: 03-28-2010, 07:19 PM
  3. Replies: 10
    Last Post: 11-01-2009, 09:42 PM
  4. JFormattedTextField / Formatter / OverWriteMode
    By Ralphw in forum AWT / Swing
    Replies: 1
    Last Post: 08-20-2009, 11:23 AM
  5. Using java.util.Formatter
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-16-2007, 02:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •