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?
Printable View
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?
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'
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....
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 !!!