Results 1 to 4 of 4

Thread: String Max Length

  1. #1

    Thread Starter
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158
    How can I set the max length of a string, in other languages you can define it when you declare a variable but how do I do it in java?

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    My VB is alittle rusty but is this how you
    declare a fixed length string in VisualBasic?

    Dim mystring as String * 10

    Well anyway....

    String objects are immutable, you cannot manipulate
    the characters of a string in place. If you need to do
    this, use a java.lang.StringBuffer instead.


    StringBuffer b = new StringBuffer("Nookie");

    Get and set induvidual charadters of the String Buffer

    b.setCharAt(0. 'P'); // b now hold Pookie!!!
    b.setLength(0) // truncate by setting the length
    // now were back to 'P'

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    what language can you specify the max length of a string in?? I know this available with controls, but not sure that is available overall.

    you can make your own class, that has an instance of a string in it, and make setText methods for that class and you can check the length of that string and if it is greater then the maximum length of what you want to allow chop and set the class instance of string to it.

    Pretty easily done....

  4. #4

    Thread Starter
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158
    billrogers
    when I said string max length I meant FIXED SIZED STRINGS, you know like those you can declare in vb and most other languages:

    I think in VB it's somthing like

    dim myString as string * 15

    I'm sorry if I wasn't clear in my post's subject.

    Can you show show me your way off doing it, as I'm new to Java I hardly know any string function, and I'm sure there nedded in order to chop/trim the extra part of the string of.

    !!! THANKS !!!

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