aspose file tools*
The moose likes Java in General and the fly likes print a string across multiple lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "print a string across multiple lines" Watch "print a string across multiple lines" New topic
Author

print a string across multiple lines

madhoo vavila
Greenhorn

Joined: Feb 20, 2004
Posts: 3
Hi!
I am trying to print a string across multiple lines. Each line has 23 characters. The string will be appended to an email

emessg.append (title.substring(0,23)).append("\t\t"); //this prints the first line , and I will add something after that

But the real problem is here
int i=0;
int j=23;
while(j<title.length())
{
i=j;
j=i+23;
if(j>title.length())
j=title.length();
emessg.append("\t\t\t").append(title.substring(i,j)).append("\n");
}

The code works fine but the string is not getting wrapped up.
Suppose if I have a word "World" at the end it is printed as
Worl
d
But I need the word in the same line.
How do I do this? Any suggestions
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Try looking at this...
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/WordUtils.html

Or this...

http://www-106.ibm.com/developerworks/java/library/j-boundaries/boundaries.html

The moral? Google is your friend.
[ July 06, 2005: Message edited by: Steve Morrow ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"madhuri"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: print a string across multiple lines