This week's book giveaway is in the Open Source forum.
We're giving away four copies of RabbitMQ in Depth and have Gavin Roy on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Re: get arguments with space contained Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Re: get arguments with space contained" Watch "Re: get arguments with space contained" New topic

Re: get arguments with space contained

Joe Cheung
Ranch Hand

Joined: Oct 18, 2002
Posts: 104
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.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Have the user input the parameters using quotes.
java ProgramName "eat apple" "eat orange" "eat banana"

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Re: get arguments with space contained