git-svn-id: https://samskivert.googlecode.com/svn/trunk@2261 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -934,6 +934,29 @@ public class StringUtil
|
|||||||
return vals;
|
return vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an array of doubles from its string representation. The array should be represented
|
||||||
|
* as a bare list of numbers separated by commas, for example:
|
||||||
|
*
|
||||||
|
* <pre>25.0, .5, 1, 0.99</pre>
|
||||||
|
*
|
||||||
|
* Any inability to parse the array will result in the function returning null.
|
||||||
|
*/
|
||||||
|
public static double[] parseDoubleArray (String source)
|
||||||
|
{
|
||||||
|
StringTokenizer tok = new StringTokenizer(source, ",");
|
||||||
|
double[] vals = new double[tok.countTokens()];
|
||||||
|
for (int i = 0; tok.hasMoreTokens(); i++) {
|
||||||
|
try {
|
||||||
|
// trim the whitespace from the token
|
||||||
|
vals[i] = Double.parseDouble(tok.nextToken().trim());
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vals;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses an array of booleans from its string representation. The array should be represented
|
* Parses an array of booleans from its string representation. The array should be represented
|
||||||
* as a bare list of numbers separated by commas, for example:
|
* as a bare list of numbers separated by commas, for example:
|
||||||
|
|||||||
Reference in New Issue
Block a user