newbie: How to know witch operator is an string

From: Johan (johankees*AT*_at_dolfijn*DOT*.nl)
Date: 10/31/03


Date: Fri, 31 Oct 2003 16:06:55 +0100

Hi,

I'm working on an very simple calculator. It has to simple math. I'm
trying to read an string from the command line and then divide it into
numbers and an operator. With the split method of String I can get the
numbers, but how do I get to know what operator is in the string. (for
example 25+5) I also tried to do this with StringTokenizer, but the same
  problem here.

...
String[] result = args[0].split("\\+|\\*|\\-|/");
double a = Double.parseDouble(result[0]);
double b = Double.parseDouble(result[1]);
if (args[0].)
System.out.println(a+b);
...

Does anyone know how to do this?

Thanks in advance,

Johan



Relevant Pages

  • TIP #185: Null Handling
    ... nulls, and command modifications for manipulating them. ... Tcl deals with strings, the universal medium for representing data. ... is know and it is an empty string, but if a respondent forgets to give ...
    (comp.lang.tcl)
  • Re: Determine how Word was launched
    ... inspect the command line used to launch Word. ... Private Declare Function GetCommandLineA Lib "kernel32" As Long ... Public Function GetCommandLineAs String ... Dim lngCmdLinePtr As Long ...
    (microsoft.public.office.developer.vba)
  • Re: Class.getMethod in classs static initializer block
    ... I just wanted to add that I had some similar code for a "command line server" project. ... static private final boolean DEBUG = true; ... {public ReturnCode runCommand(String s) ... public ReturnCode parseLine(String line) ...
    (comp.lang.java.programmer)
  • Re: New "base document" available
    ... How to go about retrieving command line parameters? ... the command line arguments (and environment variables) ... Keyword and positional parameters can be mixed in the same command line. ... clp-name points to a string containing "P1" ...
    (comp.lang.cobol)
  • A plan for handling command line options
    ... Getopt is meant to be used by calling it once for each command ... In each case the first argument is an option string and the ... provide an error handling interface that the user can access. ...
    (comp.programming)