• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with splitting the String

 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys
I want to split the string into 165 characters each.
for example


String str="Multiple constructor definitions in a class can each have a different number, or type, of arguments. When you use new, you can specify different arguments in the argument list, and the correct constructor for those arguments will be called. Multiple constructor definitions are what enabled the ShowTokens() class in the previous example to accomplish different things with the different uses of the new operator. When you create your own classes, you can define as many constructors as you need to implement the behavior of the class."

Now i want to split the string into 165 characters each..

i have written code as follows:

int s1=0;int s2=165;
for(s1=0;s2<=str.length()
{

String sm=msg.substring(s1,s2);

s2+=165;s1+=165;
out.println(sm);

}


Its giving me proble..The string is not printing the completed string data


any suggestions?

Thanks in advance
san
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What problem you are facing? For me the following piece of code working. So your code also should work as long as you avoid compilation errors:


[ March 01, 2006: Message edited by: KJ Reddy ]
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to add a line to the code. After the for loop add the
following:

out.println(msg.substr(s1) ) ;

The last bit of the string is not printed because s2 is larger than
the string length and s1 is still smaller than the string length
so the last few characters are not being preinted because of
s2 <= msg.length( )
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry msg should OBVIOUSLY be replaced with str.

a little brain freeze. I forgot what your variable was
when I went to post the reply.
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops!!! also substring not substr

I am such an idoit sometimes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!