Results 1 to 3 of 3
- 02-17-2008, 04:21 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 2
- Rep Power
- 0
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;
}
- 02-17-2008, 06:08 PM #2
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]); } } }
- 02-18-2008, 04:24 AM #3
Member
- Join Date
- Feb 2008
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Breaking down an integer
By Emily in forum New To JavaReplies: 1Last Post: 03-06-2008, 06:39 PM -
Breaking from nested switch
By javaplus in forum New To JavaReplies: 3Last Post: 02-02-2008, 08:28 AM -
Selecting parts of an image
By shaungoater in forum Java 2DReplies: 1Last Post: 12-15-2007, 10:06 PM -
iteration on huge amount of files in a folder
By tshaked in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:08 PM -
Jtree - making parts editable
By kmarie in forum AWT / SwingReplies: 1Last Post: 07-27-2007, 02:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks