-1

I've got around 50 lines of data in a text file below containing the following

Date= 1/1/2012 (dd:mm:yyyy) Time= 1:44:10 (hh:mm:ss)
Recording Started at 1:44:10 (hh:mm:ss)
X-Value = -0.525108, Y-Value = 7.746691, Z-Value = 5.863008, Timestamp(milliseconds) = 23001
X-Value = -0.755030, Y-Value = 7.861651, Z-Value = 6.016289, Timestamp(milliseconds) = 23208
X-Value = -0.448467, Y-Value = 8.551417, Z-Value = 4.943320, Timestamp(milliseconds) = 23401
Recording Stopped at 1:44:11 (hh:mm:ss)

The code I have right now uses a BufferedReader reading every line of the file but what I really want to do is extract the Y-Value, Z-Value and Timestamp(milliseconds) values from each line and then store it in some sort of data structure? What would be the best way of doing this?

unleashed
  • 915
  • 2
  • 16
  • 35

2 Answers2

0

Use String.split() with comma and white-spae as a delimiter and than split the resultant array element with = as a delimiter. Than, add the resultant array elements into an ArrayList.

String str = "X-Value = -0.525108, Y-Value = 7.746691, Z-Value = 5.863008, Timestamp(milliseconds) = 23001
";
String[] data_array = str.split(", ");    
ArrayList<String> Y_Value = new ArrayList<String>();
Y_Value.add(data_array[1].split("= ")[1]);
RanRag
  • 48,359
  • 38
  • 114
  • 167
0

It looks like you've answered your own question - use a regex (Pattern) to extract the values from each line and store it in a data structure that is appropriate for your situation. Take a look here for an example. This is assuming that you want only the values themselves and not the identifiers.

Community
  • 1
  • 1
Mitch
  • 31
  • 1
  • 6