Results 1 to 3 of 3
  1. #1
    waNnY is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    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;
    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java 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]);
            }
        }
    }

  3. #3
    waNnY is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •