|
-
Apr 15th, 2001, 05:02 PM
#1
Thread Starter
Addicted Member
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?
-
Apr 15th, 2001, 07:19 PM
#2
Dazed Member
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'
-
Apr 18th, 2001, 02:44 PM
#3
Hyperactive Member
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....
-
Apr 18th, 2001, 03:13 PM
#4
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|