• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internationalization: command usage. How many argument in main()

 
shell Johnson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have command syntax usage like this:

listAllAccount -d <date> -o <owner name> -desc <description>
and need to support internationally. What I will get from main()? a single argument or multiple argument? The BreakIterator sample in API shows that args.length =1. Is this true?
public static void main(String args[]) {
if (args.length == 1) {
String stringToExamine = args[0];
//print each word in order
BreakIterator boundary = BreakIterator.getWordInstance();
boundary.setText(stringToExamine);
printEachForward(boundary, stringToExamine);
//print each sentence in reverse order
boundary = BreakIterator.getSentenceInstance(Locale.US);
boundary.setText(stringToExamine);
printEachBackward(boundary, stringToExamine);
printFirst(boundary, stringToExamine);
printLast(boundary, stringToExamine);
}
}
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your app started similar like this:

or

?
In the first case you have 7 arguments, with
args[0].equals ("listAllAccount"), args[1].equals ("-d").
In the second you have 6 arguments.

and if not?
If the first form is right, your args[0] and stringToExamine is 'listAllAccount'.
If you run your code you may insert a 'print'-Statement to verify.
 
shell Johnson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As your explanation, java will recognize localized "white space" or "word break" to break one single line into several arguments. Is this true? It seems that is it not what the BreakIterator sample shows. I'm on US locale. I always get 7 arguments. Is this true that I always get 7 arguments from all different locale?
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This breaking apart of the parameters happens before Java kicks in.
That's done by the operating system.
To go one step farther, this is even OS dependant.
If you have a directory with a.txt and b.txt files and you decide to call

you will get
args[0] = a.txt, args[1] = b.txt on the UNIX shell
and
args[0] = *.txt on Windows
Ballyhoo,
J.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic