Results 1 to 4 of 4

Thread: String length

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Penang, Malaysia
    Posts
    51
    Hi,
    How do i set a fix length for a particular string?
    eg.
    abc
    defg
    hifklmn

    i want to make all i nsame length?

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    you could extend the string class, making your own class which you could add functionality to allow that, that is the best oo approach.

  3. #3
    Guest

    Thumbs up Rename to FixedString.java

    String is a final class, which means it cannot be extended.

    But keeping with billrogers' idea, you can make your own class, say "FixedString" which has a private String member and you only allow modification upto the original size of the FixedString through a setter (depending on your needs, filling the remaining spots with spaces).

    I was about to write such a class when I realized you might want to use the existing StringBuffer class.

    Wow
    This much free time at work.
    Usage:
    FixedString fs = new FixedString("SomeString", maxLengthAsINTEGER);
    Say you want them all to have a length of 7:
    eg.
    abc
    defg
    hifklmn
    use:
    FixedString fs1 = new FixedString("eg.", 7);
    FixedString fs2 = new FixedString("abc", 7);
    etc.
    There are also constructors for a given integer length or a given string. The max length is determined by the length you originally set or the length of the original string, respectively.

    Rather than play with javadoc, I'll just give you what I have now.
    Attached Files Attached Files

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Penang, Malaysia
    Posts
    51

    Date

    thank a lot, i finally solve String and integer problem.
    But i have one more question about date.

    I retrieve a date from system date, how do i convert it to previouse month? (i need it to retrieve particular data to print report on 1st of every month).

    note: firstly the date format is yyyymmdd to match the format in database, when display on report, i need to change to MMMyyyy format.

Posting Permissions

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



Click Here to Expand Forum to Full Width