• Post Reply Bookmark Topic Watch Topic
  • New Topic

print a string across multiple lines  RSS feed

 
madhoo vavila
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!