Results 1 to 6 of 6
- 04-08-2012, 11:12 AM #1
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Splitting an string of number into multiple lines
I got one string test="101010101010101010101010101010101010101010" it's 20x10 and want to split it into one output that shows 5x10's in a line.
Been thinking on using .charAt() in one for loop but having troubble twisting my ideas on getting it done.
Been doing java tasks all easter, since the weather have sucked too mutch.
- 04-08-2012, 11:47 AM #2
Re: Splitting an string of number into multiple lines
For subdividing a String at specific lengths, use substring(...).
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-08-2012, 03:17 PM #3
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Re: Splitting an string of number into multiple lines
here is what i've gotten into so far, one eased down code cut.
the whole program was to enter 20 numbers in between 20 and 50. store them in one array and print them out in one messagebox with only 5 numbers each line.Java Code:class stringedit{ public static void main(string[]args){ String testString = "20 21 22 23 24 25 26 27 28 29"; String finalString=""; // MAX 5 NUMBERS EACH LINE int testlength = testString.length(); for (int i=0;i<testlength;i++){ finalString = finalString+testString.substring(15)+"\n" }// END FOR }// END MAIN }//END STRINGEDIT
having some troubble on the FOR loop.
also, are my thoughts so far going the right direction ?
-
Re: Splitting an string of number into multiple lines
Where's your array? Will the user be entering numbers separated by spaces? If so, look into String#split(...) to create the String array for you.
- 04-08-2012, 04:09 PM #5
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Re: Splitting an string of number into multiple lines
that was just one example code. had to make it so i could translate into English also.
I've entered the numbers 20 times seperatly and it's stored in one array.
and then pulled out of the array and into one string with one " " in between each number so they won't be clustered.
also made one check that if the number typed in ain't in between 20 and 50 you will get one message and type it in again.
also trying not to be rude to get people to code for me but sending me in the right direction and maybe one concept code for the current problem at hand.
- 04-09-2012, 10:30 AM #6
Member
- Join Date
- Oct 2011
- Location
- Tromsų
- Posts
- 41
- Rep Power
- 0
Re: Splitting an string of number into multiple lines
and then problem is solved, had to use another forum for some help.Java Code:class stringedit{ public static void main(string[]args){ String testString = "20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39"; String finalString=""; // MAX 5 NUMBERS EACH LINE int testlength = testString.length(); for (int i=0;i<testlength;i++){ finalString = finalString+testString.substring(i,i+14)+"\n" i+=14; }// END FOR }// END MAIN }//END STRINGEDIT
might be the good part of internet. =)
Similar Threads
-
Splitting program into multiple files
By ourimaler in forum New To JavaReplies: 3Last Post: 02-24-2012, 11:50 AM -
Easy Question! Print out file, count number of lines, number of spaces w/ Scanner
By LogicalOutlier in forum New To JavaReplies: 8Last Post: 01-21-2012, 01:14 AM -
Splitting number
By cshoya in forum New To JavaReplies: 2Last Post: 06-06-2011, 03:23 AM -
String Splitting
By A.M.S in forum New To JavaReplies: 1Last Post: 12-04-2009, 07:17 AM -
How to split a string into multiple lines of x characters each
By JackJ in forum New To JavaReplies: 3Last Post: 12-17-2007, 02:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks