JAVA help?

Soldato
Joined
28 Nov 2005
Posts
13,001
I need a bit of pointer, i have to make something in java where you enter 2 words but the whole thing has to be below 37characters...and between the two words the extra characters are used up by dots?

Im a bit stuck :(
 
String.split() and String.substring()

Quick example to get you started.

Code:
public String shortenString(String myString)
{
    if ((len = myString.length()) > 37)
    {
        return myString.substring(0, 34) + "..." + myString.substring(len - 3, len);
    }
    else
    {
        return myString;
    }
}

use lastIndexOf(" ") and a few sums to work out words.
 
Back
Top Bottom