Results 1 to 3 of 3
- 10-25-2010, 09:27 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
Spliting a string (45 Characters)
Hi,
I'm trying to use the substring() method in order to split a string depending on how many characters it contains.
The String is normally 285 characters and i would like to split it and create a possible variable out of it.
In each variable i want to save 45 characters starting bei: 0 till the end of the String... id do have this simple code which is really not profesioneel and i would like to create the variables which are possible dynamically. it must be possible with for or while, but i really can't get it, as i'm not really a profi in java/Jsp.
Would anybody be so kind and help me please?:)
I tried it with a for/while, but i'm getting an error which i can't solve.:confused:XML Code:<% String s1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. Lorem Ipsum is simply dummy text of the printing and typesetting industry"; String countSrt1; String countSrt2; String countSrt3; String countSrt4; //out.println("\"" + s1 + "\"" + " is " + s1.length() + " characters long."); /* if(s1.length()<= 285){ countSrt1 = s1.substring(0, 45); out.println("<b>The first String: </b>" + countSrt1 + "<br><br>"); countSrt2 = s1.substring(countSrt1.length(), 90); out.println("<b>The second String: </b>" + countSrt2 + "<br><br>"); countSrt3 = s1.substring(91, 135); out.println("<b>The third String: </b>" + countSrt3 + "<br><br>"); countSrt4 = s1.substring(136, 180); out.println("<b>The fourth String: </b>" + countSrt4 + "<br><br>"); } %>
Many Thanks
BobAmin
- 11-19-2010, 09:09 AM #2
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
Check ur condition in if statement. i have tried ur code its working fine with out the if condition. So, there is some problem with that.
Good Luck!!!
- 11-20-2010, 09:45 AM #3
the string s1 has a length of 319 chars, so your if-statement (s1.length()<= 285) will not become true.
Similar Threads
-
How to check whether the string contains only the specified characters ????
By j_kathiresan in forum New To JavaReplies: 1Last Post: 04-30-2010, 03:21 PM -
Swap characters in a string.
By Sdannenberg3 in forum New To JavaReplies: 4Last Post: 03-04-2010, 08:49 PM -
spliting a string and checking each token's format
By Implode in forum New To JavaReplies: 1Last Post: 10-18-2009, 08:41 PM -
how to get the characters one by one from a String?
By Somitesh Chakraborty in forum New To JavaReplies: 3Last Post: 08-20-2008, 08:56 PM -
Getting all characters in a String
By Alayna in forum New To JavaReplies: 2Last Post: 05-20-2007, 11:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks