public static void main(String[] args) {
String from = "";
String to = "";
String subject = "";
String body = "";
System.out.println("number of args : " + args.length);
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("From:")) {
from = args[i].substring(5);
System.out.println("MAIL FROM: " + from);
} else if(args[i].startsWith("To:")) {
to = args[i].substring(2);
System.out.println("RCPT TO: " + to);
} else if(args[i].startsWith("Subject:")) {
subject = args[i];
System.out.println("SUBJECT: " + subject.substring(8));
} else if (args[i].startsWith("Body:")) { //The rest
for (int j = i; j < args.length; j++) {
body += args[j];
}
System.out.println(body);
}
}
我的问题是 args 的长度
当我在命令行中输入这个:
java test To:a@a.com From:b@b.com Subject:hi Body:hi I see you
我的输出是这样的:
number of args : 7
我的预期输出是这样的:
number of args: 4
我可以做些什么来排除你好我看到你的 args 长度吗?我不想使用引号。