how to do this?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kenny_C
Posted On:   Sunday, January 19, 2003 06:23 PM

I am holding a forum, and user can submit their content with a subject heading....if the subject heading is too long, it take 3 to 4 rows to display the heading...Now, if I want to change it into, for instance, the heading from "I am now pulling myself into the depth of this great big Ocean" to "I am now pulling ..."

How can i do it?

The subject variable is
String subject = qna.getSubject();

Re: how to do this?

Posted By:   James_Bayer  
Posted On:   Sunday, January 19, 2003 09:26 PM


StringBuffer sb = new StringBuffer();

StringTokenizer st = new StringTokenizer( subject );
while( st.hasMoreTokens() )
{
String strToken = st.nextToken();

//replace 20 with the appropriate max line length
if( sb.length() + strToken.length() < 20 )
sb.append( strToken );
else sb.append( " ..." );
}
//sb.toString() will give you the string to display

About | Sitemap | Contact