Reputation: 12395
I want to split the input String values separated by one of these char
,
;
blankspace
\
/
in a double array
My code for ,
is
String valueS[] = input.split(",");
int n = valueS.length;
double yvalue[] = new double[n];
double sum = 0;
for (int i = 0; i < n; i++) {
yvalue[i] = Double.parseDouble(valueS[i]);
}
What is the right syntax that I should put in
String valueS[] = input.split(",");
to split also with the others listed chars?
Upvotes: 1
Views: 1501
Reputation: 13269
To actually answer your question, String.split (String regularExpression)
uses a regular expression to determine what to split the array by.
This regular expression below will try to split the array by any one of these characters:
It is using an "Enumeration" that will match 1 or more of these characters in a row, and then split on them:
String[] valueS = input.split("[,;\\s\\\\/]+");
Hope this helps.
Upvotes: 3