Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008, 05:21 PM
Member
 
Join Date: Feb 2008
Posts: 2
Rep Power: 0
waNnY is on a distinguished road
Unhappy 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
  #2 (permalink)  
Old 02-17-2008, 07:08 PM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
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
Rep Power: 0
waNnY is on a distinguished road
Default
Hi hardwired,
Thanx 4 ur concern..Its really2 help me..;>
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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 +2. The time now is 06:41 PM.



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