C
Colin
Hello,
I'm working on a Java program that supports the GTP protocol (Protocol
for programs playing the Go board game). GTP supports commands of the
following format:
[id] command_name [args]
where id is an integer, command_name is a string, args is a space-
separated list of strings, and elements in [] are optional.
I'm using StringTokenizer, and I'm wondering about the best way to
determine if the first element is an integer (id has been given) or a
string (it was omitted). I can think of a few ways to do this, but
none of them seem very elegant. For example, I could extract the
first character of the token and see if it is a digit. What happens
if I use Integer.parseInt(token) and token is a string? Is an
exception thrown?
What do you think is the best way to handle this?
Thanks,
Colin
I'm working on a Java program that supports the GTP protocol (Protocol
for programs playing the Go board game). GTP supports commands of the
following format:
[id] command_name [args]
where id is an integer, command_name is a string, args is a space-
separated list of strings, and elements in [] are optional.
I'm using StringTokenizer, and I'm wondering about the best way to
determine if the first element is an integer (id has been given) or a
string (it was omitted). I can think of a few ways to do this, but
none of them seem very elegant. For example, I could extract the
first character of the token and see if it is a digit. What happens
if I use Integer.parseInt(token) and token is a string? Is an
exception thrown?
What do you think is the best way to handle this?
Thanks,
Colin