Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008, 05:21 PM
Member
 
Join Date: Feb 2008
Posts: 2
waNnY is on a distinguished road
Breaking huge text into multiple parts.Please help..
Hi all..i'm urgently need any attention here..pliz help to solve this problem..
The description of my problem is like dis >> let say now i have 100 length of a text. Now , i need to break it into multiple parts, accordingly to the max lenght of a part for one time is 30.So, it should be to returned like dis >>
text [1]="blablabla.." -->text.length =30
text [2]="blablabla.." -->text.length =30
text [3]="blablabla.." -->text.length =30
text [4]="blablabla.." -->text.length =10

I have write a pieces of code that may explain what i try to do..but its not really work..i hope anybody out there can help me..thanks a lot..

code:
for (int i=0; i<fullMsg.length(); i++){
singlLen ++;
}

if (singlLen == LEN-1){

System.out.print("splitMsg: i="+i+"\n");
System.out.print("splitting new msg["+msgCnt+"]="+fullMsg.substring(beginPos, i)+"\n");

msg[msgCnt] = fullMsg.substring(beginPos, i);
singlLen = 0;
msgCnt ++;
beginPos = i+1;
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-17-2008, 07:08 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
public class SplitItUp { public static void main(String[] args) { String text = "The description of my problem is like " + "dis >> let say now i have 100 length of a text. " + "Now , i need to break it into multiple parts, " + "accordingly to the max lenght of a part for one " + "time is 30."; int lineLength = 30; int length = text.length(); int size = length/lineLength; if(length % lineLength != 0) // partial line at end size++; String[] lines = new String[size]; for(int j = 0; j < size; j++) { int start = j * lineLength; int end = start + lineLength; if(end > length) end = length; lines[j] = text.substring(start, end); System.out.println(lines[j]); } } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-18-2008, 05:24 AM
Member
 
Join Date: Feb 2008
Posts: 2
waNnY is on a distinguished road
Hi hardwired,
Thanx 4 ur concern..Its really2 help me..;>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Breaking down an integer Emily New To Java 1 03-06-2008 07:39 PM
Breaking from nested switch javaplus New To Java 3 02-02-2008 09:28 AM
Selecting parts of an image shaungoater Java 2D 1 12-15-2007 11:06 PM
iteration on huge amount of files in a folder tshaked Advanced Java 1 08-07-2007 08:08 PM
Jtree - making parts editable kmarie AWT / Swing 1 07-27-2007 03:34 AM


All times are GMT +3. The time now is 02:48 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org