d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > String To Double
Prev12
Add Reply New Topic New Poll
Member
Posts: 2,264
Joined: Jul 7 2007
Gold: 26.00
Nov 3 2014 04:39pm
Quote (Eep @ Nov 3 2014 06:32pm)
:wacko: huh...

you are correct, after looking online, "\\s+" is the correct java convention.



Maybe post your input file?

I am heading to class and maybe someone else can help you finish it. String.split() should net you the proper array though if the regex worked for your input file, so I am not sure what you got everything at index 0.


My input file is copy pasted from this:
https://archive.ics.uci.edu/ml/machine-learning-databases/statlog/segment/segment.dat

I could also just try to read them as double though I keep getting a type mismatch whenever i try that

This post was edited by axumo0 on Nov 3 2014 04:43pm
Member
Posts: 2,264
Joined: Jul 7 2007
Gold: 26.00
Nov 3 2014 05:45pm
FINALLY GOT IT, i ended up doing it another way but it works, Thanks for your help Eep!
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Nov 13 2014 08:02pm
Quote (axumo0 @ Nov 3 2014 04:10pm)
Quick Question;

If I have a string of numbers for example:

18.0  8  307.0      130.0      3504.      12.0  70  1

How would i convert each of these numbers to a double and put each one into a separate double array?


In Java:
Scanner data = new Scanner(pathToFile);
String numbers = data.nextLine();
//The entire string is now in the string numbers
String[] splitNums = numbers.split(" ");
double[] nums;
for(int i=0; i<splitNums.length; i++)
{
//Parse each element of splitNums into double array
nums[i] = Double.parseDouble(splitNums[i]);
}
Member
Posts: 6,742
Joined: Mar 23 2008
Gold: 45.00
Nov 21 2014 03:54pm
Parse it.
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll