Results 1 to 3 of 3
  1. #1
    dricco is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default Formatting java command line output - Multi line string

    Is it possible to format output of a string across multiple lines. Writting a script in java that's going to output information to the user in the command line (Max width 80 characters). Some of my strings are longer that 80 character and want to display them accross multiple lines. Won't be using a db. bad example below, sorry!!!



    Java Code:
    Name       Age       Address            Active
    ____        ___     ______             _____
    
    John        24       No .1 The         Yes
                            house, the 
                            World      
    
    Paul         26       unknown           No


    Is this format possible with printf formatter?

    thanks in advance..

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default

    Yes, I think it is. Have you tried it?
    You will have to break the String up and insert leading spaces for the continued lines

  3. #3
    dricco is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    Got the first part (converting to multiple lines), working on the second now

    Java Code:
    	private List<String> SplitIntoLines(String convertToLines) {
    		
    		List<String> convertedToLines = new ArrayList<String>();
    		char[] charArray = convertToLines.toCharArray();
    		int start = 0;
            // start with 
    		for (int i = 20; i < charArray.length; i++) {
    			if (charArray[i] == ' ') {
    				convertedToLines.add(convertToLines.substring(start, i));
    				start = i+1;
    				i += 20;
    			}
    		}
    		convertedToLines.add(convertToLines.substring(start));
    		return convertedToLines;
    	}

Similar Threads

  1. Command line interface in Java
    By simmi in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 07:07 AM
  2. java command line arguments
    By Vipul03 in forum New To Java
    Replies: 1
    Last Post: 02-22-2010, 02:00 PM
  3. Multi Valued Command Line arguments
    By joey86 in forum Advanced Java
    Replies: 9
    Last Post: 01-08-2010, 12:07 AM
  4. Java command line
    By agouzoul in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 12:12 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

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