This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Re: get arguments with space contained

 
Joe Cheung
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I am writing a java program that read user input by the mean of arguments, e.g. java ProgramName arg[0] arg[1]....
However, the input parameter may contain space, e.g. java ProgramName eat apple eat orange eat banana, that the program should read it as three parameters "eat apple", "eat orange" and "eat banana". Unfortunately, Java read it as six parameters instead as the space characters. How can I read the parameters correctly as I intended.
Regards,
Joe
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have the user input the parameters using quotes.
java ProgramName "eat apple" "eat orange" "eat banana"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic