How to resize one String already defined?
Well my question is simple but I can'f found any way to solve this little problem :D, I will apreciate any kind of help / tip.
I have one String like:
Code:
String title = "blabla bla bla"
Latter I need use the this String in other place but I can use it only if his length is < 29, so if his length is more big than 29 I want just delete the extra "characters" inside the String, how I can do this?
Thanks
Re: How to resize one String already defined?
First a little conceptual matter: Strings in Java don't change their length (or the characters they contain for that matter). They are said to be immutable (unchanging) which is often a very good thing for instances to be.
So if you want to use the string, but it's too long you have to create another string to be used. A common idiom (that users will understand) is to use an ellipsis. If you have a string like "The quick brown fox jumps over the lazy dog" and you want to use it in a context where a maximum of 28 characters is allowed you might construct the string "The quick brown fox jumps...".
Have a look in the String class for useful methods.
Re: How to resize one String already defined?
I think what you need is the substring() method of the String class.