Results 1 to 3 of 3
  1. #1
    BobAmin is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default 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?:)

    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>");
            }
        
         %>
    I tried it with a for/while, but i'm getting an error which i can't solve.:confused:

    Many Thanks
    BobAmin

  2. #2
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

    Default

    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!!!

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    the string s1 has a length of 319 chars, so your if-statement (s1.length()<= 285) will not become true.

Similar Threads

  1. Replies: 1
    Last Post: 04-30-2010, 04:21 PM
  2. Swap characters in a string.
    By Sdannenberg3 in forum New To Java
    Replies: 4
    Last Post: 03-04-2010, 09:49 PM
  3. spliting a string and checking each token's format
    By Implode in forum New To Java
    Replies: 1
    Last Post: 10-18-2009, 09:41 PM
  4. how to get the characters one by one from a String?
    By Somitesh Chakraborty in forum New To Java
    Replies: 3
    Last Post: 08-20-2008, 09:56 PM
  5. Getting all characters in a String
    By Alayna in forum New To Java
    Replies: 2
    Last Post: 05-20-2007, 12:49 PM

Posting Permissions

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