Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need urgent help regarding java word wrap function.. URGENT

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Need urgent help regarding java word wrap function.. URGENT

    i have a doubt regarding word wrap in java. Here is the code i have written....

    ************************************************** ****************************************
    public String Enter_LF_into_content(String inbound, Container container) {

    String outbout = "";
    int counter = inbound.length()/128;

    for (int a=0;a<counter;a++)
    {
    outbound=outbound.concat(inbound.substring(a*128,( a+1)*128)).concat("\n");
    }

    outbound=outbound.concat(inbound.substring(counter *128));
    return outbound;

    }
    ************************************************** ************************
    the above code wraps up string from 128th character but the problem is, it doesnt take care of the words it simply cuts the string from 128th position.
    I need some custom code which can wrap the string by taking care of the words.
    Plz guyzzzz.... i need help... its very urgent....


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Need urgent help regarding java word wrap function.. URGENT

    java text wrapping - Google Search
    Is there a text wrap function in the java standard library? - Stack Overflow - there is no Java line wrapping
    How to Use Text Areas (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) - there is Java line wrapping

    If you really have to write that code yourself and your requirement is only to wrap console text, try using String.lastIndexOf(int, int) and finding the position of the last space from your right margin (your text width) in your to-be-wrapped text, and breaking the text there.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need urgent help regarding java word wrap function.. URGENT

    Hi Sean,
    Thank you for the reply. Actually i am an SAP ABAPer and there is a little requirement which can be full filled using java only.
    Can you please provide a little addition in above code that if the 128th character is not space then the code should proceed to the next character untill it finds the space. once the space is found, the code would remember the position and cut the string from there.
    This whole procedure will be in loop unless the whole string is covered and every loop will begin with 128 character size and will increase upto the first occurrence of space after 128 character. Thank you in advance.

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Need urgent help regarding java word wrap function.. URGENT

    Can you please provide a little addition in above code
    If you need little bits of code to be produced urgently, your best option is probably something like liveperson.com

Similar Threads

  1. [SOLVED] need help urgent
    By rupa in forum Java Servlet
    Replies: 1
    Last Post: January 19th, 2011, 02:41 PM
  2. Need urgent help in assignment of JAVA, any idea suggestion plz
    By aesthete in forum Java Theory & Questions
    Replies: 2
    Last Post: January 6th, 2011, 05:58 AM
  3. Urgent need a java regex pattern
    By mallikarjun_sg in forum Java Theory & Questions
    Replies: 1
    Last Post: May 6th, 2010, 05:51 AM
  4. [URGENT] - Problem accessing web sites with Java!
    By jguilhermemv in forum Java Networking
    Replies: 0
    Last Post: March 5th, 2010, 04:43 PM
  5. Urgent Help needed with java codes
    By makarov in forum Java Theory & Questions
    Replies: 0
    Last Post: November 13th, 2009, 07:23 AM

Tags for this Thread