Results 1 to 2 of 2

Thread: Argument help!

  1. #1
    deeevo is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default Argument help!

    Hi, I'm wondering how I can get the from line above the rcpt to line?

    Java Code:
    public class ArgsExample {
    	public static void main(String[] args) {
    		String from = "";
    		String to = "";
    		String subject = "";
    		String emailText = "";
    		System.out.println("number of args " + args.length);
    		for (int i = 0; i < args.length; i++) 
    		{
    			if (args[i].startsWith("From:")) {
    				from = args[i];
    				System.out.println("MAIL " + from);
    			} else if (args[i].startsWith("To:")) {
    				to = args[i];
    				System.out.println("RCPT " + to);
    			} else if (args[i].startsWith("Subject:")) {
    				subject = args[i];
    				System.out.println(subject);
    			} else { // The rest
    					emailText += args[i]+" ";
    			}
    		}// for
    		System.out.println(emailText);
    	}// main
    }
    The argument line is:
    java ArgsExample To:peter999@gmail From:1234567@yahoo.com Subject:Meeting Body:See you at 1pm

    The output is:
    number of args ###
    RCPT TO: peter999@gmail
    MAIL FROM: 1234567@yahoo.com
    Subject: Meeting
    Body: See you at 1pm

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Argument help!

    Don't print the arguments as you check them (in the loop), but print them afterwards.

    kind regards,

    Jos

    ps. b.t.w. that output wasn't produced by your program.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Argument Passing
    By shavindra in forum New To Java
    Replies: 2
    Last Post: 01-05-2013, 09:24 AM
  2. Function as argument
    By MarsTeam in forum Advanced Java
    Replies: 2
    Last Post: 06-05-2010, 08:33 PM
  3. Function as argument?
    By martypapa in forum AWT / Swing
    Replies: 2
    Last Post: 02-07-2010, 10:02 AM
  4. Method as an argument?
    By StokedOnMe in forum New To Java
    Replies: 13
    Last Post: 09-18-2009, 06:29 AM

Tags for this Thread

Posting Permissions

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