Mr.Wong
12-08-2001, 01:06 PM
How could i get the numbers out of a string that looks like this??
[Point2D.Double[-10.0, 0.0], Point2D.Double[10.0, 0.0]]
I thought about checking each char but now my head hurts so i thought i'd post and try and get some help.
bwkaz
12-08-2001, 02:49 PM
Try a StringTokenizer to split off the numbers fron everything else, and then use Integer.parseInt() on the String returned from nextToken(). Maybe like this:
StringTokenizer st = new StringTokenizer(<input string>, "[,] ");
// This sets the brackets, space, and comma as the token delimiters
while(st.hasMoreTokens()) {
try
System.out.println(Integer.parseInt(st.nextToken() ));
catch(NumberFormatException e) {}
}
You can put stuff in the brackets after the catch if you don't just want to ignore number format exceptions. The way it's set up, it will try to convert everything, including the character strings (like "Point2D.Double"), and this is obviously going to fail, so I just ignore that exception.
HTH, if you need more info, try the Sun online JDK documentation at http://java.sun.com
[ 08 December 2001: Message edited by: bwkaz ]